Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RESOLVED] Updated gen command parameters table #142 #143

Merged
merged 3 commits into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/generamba/cli/gen_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def gen(module_name, template_name)
module_info = ModuleInfoGenerator.new(code_module)
template = ModuleTemplate.new(template_name, module_info.scope)

parameters = GenCommandTableParametersFormatter.prepare_parameters_for_displaying(rambafile)
parameters = GenCommandTableParametersFormatter.prepare_parameters_for_displaying(code_module, template_name)
PrintTable.print_values(
values: parameters,
title: "Summary for gen #{module_name}"
Expand Down
26 changes: 20 additions & 6 deletions lib/generamba/helpers/gen_command_table_parameters_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
module Generamba
# Provides methods for prepare parameters for displaying in table.
class GenCommandTableParametersFormatter
require 'json'

# This method prepared parameter for displaying
def self.prepare_parameters_for_displaying(parameters)
params = parameters.clone
def self.prepare_parameters_for_displaying(code_module, template_name)
params = {}

params['Targets'] = code_module.project_targets.join(',')
params['Module path'] = code_module.module_file_path

if code_module.module_file_path != code_module.module_group_path
params['Module group path'] = code_module.module_group_path
end

templates = []
params['Test targets'] = code_module.test_targets.join(',') if code_module.test_targets
params['Test file path'] = code_module.test_file_path if code_module.test_file_path

params['templates'].each do |param|
templates.push(param['name'])
if code_module.test_file_path != code_module.test_group_path
params['Test group path'] = code_module.test_group_path
end

params['templates'] = templates.join("\n")
params['Template'] = template_name

if code_module.custom_parameters
params['Custom parameters'] = code_module.custom_parameters.to_json
end

params
end
Expand Down
40 changes: 31 additions & 9 deletions spec/gen_command_table_parameters_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
require_relative 'spec_helper'
require 'json'
require 'generamba/code_generation/code_module.rb'
require 'generamba/constants/rambafile_constants.rb'

describe 'GenCommandTableParametersFormatter' do

describe 'method prepare_parameters_for_displaying' do
it 'should convert array of hash to array of strings' do
expected_string = "name1\nname2"
expected_params = {}

parameters = {
'templates' => [
{'name' => 'name1', 'path' => 'path1'},
{'name' => 'name2', 'path' => 'path2'}
]
}
expected_params['Targets'] = 'Target'
expected_params['Module path'] = Pathname.new('Project/name')
expected_params['Module group path'] = Pathname.new('Project/Modules/name')
expected_params['Test targets'] = 'TargetTests'
expected_params['Test file path'] = Pathname.new('ProjectTests/name')
expected_params['Test group path'] = Pathname.new('ProjectTests/Modules/name')
expected_params['Template'] = 'Template'
expected_params['Custom parameters'] = {:key => 'value'}.to_json

params = Generamba::GenCommandTableParametersFormatter.prepare_parameters_for_displaying(parameters)
rambafile = {}
rambafile[Generamba::PROJECT_NAME_KEY] = 'project'
rambafile[Generamba::PROJECT_FILE_PATH_KEY] = 'file_path'
rambafile[Generamba::PROJECT_GROUP_PATH_KEY] = 'group_path'
rambafile[Generamba::PROJECT_TARGET_KEY] = 'Target'
rambafile[Generamba::PROJECT_FILE_PATH_KEY] = 'Project'
rambafile[Generamba::PROJECT_GROUP_PATH_KEY] = 'Project/Modules'
rambafile[Generamba::TEST_TARGET_KEY] = 'TargetTests'
rambafile[Generamba::TEST_FILE_PATH_KEY] = 'ProjectTests'
rambafile[Generamba::TEST_GROUP_PATH_KEY] = 'ProjectTests/Modules'

expect(params['templates']).to eq(expected_string)
options = {}
options[:custom_parameters] = {:key => 'value'}

code_module = Generamba::CodeModule.new('name', 'description', rambafile, options)
template_name = 'Template'

params = Generamba::GenCommandTableParametersFormatter.prepare_parameters_for_displaying(code_module, template_name)

expect(params).to eq(expected_params)
end
end

Expand Down