Class: Generamba::ModuleGenerator
- Inherits:
-
Object
- Object
- Generamba::ModuleGenerator
- Defined in:
- lib/generamba/module_generator.rb
Overview
Responsible for creating the whole code module using information from the CLI
Instance Method Summary collapse
- #generate_module(name, code_module, template) ⇒ Object
- #process_files_if_needed(files, name, code_module, template, project, targets, group_path, dir_path) ⇒ Object
Instance Method Details
#generate_module(name, code_module, template) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generamba/module_generator.rb', line 11 def generate_module(name, code_module, template) # Setting up Xcode objects project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path) # Configuring file paths FileUtils.mkdir_p code_module.module_file_path if code_module.test_file_path != nil FileUtils.mkdir_p code_module.test_file_path end # Creating code files puts('Creating code files...') process_files_if_needed(template.code_files, name, code_module, template, project, code_module.project_targets, code_module.module_group_path, code_module.module_file_path) # Creating test files included_tests = code_module.test_targets && code_module.test_group_path && code_module.test_file_path if included_tests puts('Creating test files...') process_files_if_needed(template.test_files, name, code_module, template, project, code_module.test_targets, code_module.test_group_path, code_module.test_file_path) end # Saving the current changes in the Xcode project project.save puts 'Module successfully created!' puts "Name: #{name}".green puts "Module file path: #{code_module.module_file_path}".green puts "Module group path: #{code_module.module_group_path}".green puts "Test file path: #{code_module.test_file_path}".green if code_module.test_file_path puts "Test group path: #{code_module.test_group_path}".green if code_module.test_group_path end |
#process_files_if_needed(files, name, code_module, template, project, targets, group_path, dir_path) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/generamba/module_generator.rb', line 59 def process_files_if_needed(files, name, code_module, template, project, targets, group_path, dir_path) # It's possible that current project doesn't test targets configured, so it doesn't need to generate tests. # The same is for files property - a template can have only test or project files if targets.count == 0 || files == nil || files.count == 0 || dir_path == nil || group_path == nil return end XcodeprojHelper.clear_group(project, targets, group_path) files.each do |file| unless file[TEMPLATE_FILE_PATH_KEY] directory_name = file[TEMPLATE_NAME_KEY].gsub(/^\/|\/$/, '') file_group = dir_path.join(directory_name) FileUtils.mkdir_p file_group XcodeprojHelper.add_group_to_project(project, group_path, dir_path, directory_name) next end file_group = File.dirname(file[TEMPLATE_NAME_KEY]) module_info = ModuleInfoGenerator.new(code_module) # Generating the content of the code file and it's name file_name, file_content = ContentGenerator.create_file(file, module_info.scope, template) file_path = dir_path.join(file_group).join(file_name) # Creating the file in the filesystem FileUtils.mkdir_p File.dirname(file_path) File.open(file_path, 'w+') do |f| f.write(file_content) end file_is_resource = file[TEMPLATE_FILE_IS_RESOURCE_KEY] # Creating the file in the Xcode project XcodeprojHelper.add_file_to_project_and_targets(project, targets, group_path, dir_path, file_group, file_name, file_is_resource) end end |