Class: Topographer::Generators::Install
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Topographer::Generators::Install
- Includes:
- Thor::Actions, Helpers
- Defined in:
- lib/topographer/generators/install/install.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_imports ⇒ Object
- #add_mappings ⇒ Object
- #add_runners ⇒ Object
- #add_strategies ⇒ Object
- #ignored_strategy_symbols ⇒ Object
Methods included from Helpers
Class Method Details
.source_root ⇒ Object
10 11 12 |
# File 'lib/topographer/generators/install/install.rb', line 10 def self.source_root File.("../../templates", __FILE__) end |
Instance Method Details
#add_imports ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/topographer/generators/install/install.rb', line 101 def add_imports import_base_path = subdirectory_path('.','base.rb') ui_import_path = subdirectory_path('.', 'user_interface_import.rb') commandline_import_path = subdirectory_path('.', 'commandline_import.rb') @namespace_files += [import_base_path, ui_import_path, commandline_import_path] template('import_base.rb.erb', import_path(import_base_path)) template('user_interface_import.rb.erb', import_path(ui_import_path)) template('commandline_import.rb.erb', import_path(commandline_import_path)) template('imports.rb.erb', File.join('./lib/', 'imports.rb'), { namespace_files: @namespace_files }) template('log_display.erb', File.join('./app/views/shared', '_import_log_display.html.erb')) end |
#add_mappings ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/topographer/generators/install/install.rb', line 47 def add_mappings mapping_base_path = subdirectory_path('mappings/', 'base.rb') mapping_files = [mapping_base_path] config_file = File.join(destination_root, 'config/environment.rb') is_rails = File.exists?(config_file) if is_rails require_relative config_file require 'active_support' [:models].each do |model| model_class = model.classify.constantize model_path = subdirectory_path('mappings/', "#{model.downcase}.rb") filepath = import_path(model_path) mapping_files << model_path template('mapping.rb.erb', filepath, { model_class: model_class, strategy_classes: @strategy_classes }) end template('rails_mapping_base.rb.erb', import_path(mapping_base_path)) else say 'Unable to generate model mappings outside of a Rails project' template('mapping_base.rb.erb', import_path(mapping_base_path)) end add_namespace_module('Mappings', mapping_files) end |
#add_runners ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/topographer/generators/install/install.rb', line 79 def add_runners runner_base_path = subdirectory_path('runners/', 'base.rb') runner_files = [runner_base_path] template('runner_base.rb.erb', import_path(runner_base_path)) @strategy_class_names.each do |strategy_class| filename = "#{underscore_name(strategy_class)}.rb" runner_path = subdirectory_path('runners/', filename) filepath = import_path(runner_path) runner_files << runner_path template('runner.rb.erb', filepath, { strategy_class: strategy_class, import_name: underscore_name(strategy_class) }) end add_namespace_module('Runners', runner_files) end |
#add_strategies ⇒ Object
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 |
# File 'lib/topographer/generators/install/install.rb', line 18 def add_strategies strategy_module = Topographer::Importer::Strategy strategy_files = [] @strategy_classes = [] @strategy_class_names = [] @namespace_files = [] strategy_module.constants(false).each do | constant_symbol | unless ignored_strategy_symbols.include?(constant_symbol) constant = strategy_module.const_get( constant_symbol ) if constant.is_a? Class @strategy_classes << constant @strategy_class_names << constant_symbol.to_s filename = "#{underscore_name(constant_symbol.to_s)}.rb" strategy_path = subdirectory_path('strategy/', filename) filepath = import_path(strategy_path) strategy_files << strategy_path template('strategy_class.rb.erb', filepath, { class_name: constant_symbol.to_s, base_class_name: constant.to_s }) end end end add_namespace_module('Strategy', strategy_files) end |
#ignored_strategy_symbols ⇒ Object
14 15 16 |
# File 'lib/topographer/generators/install/install.rb', line 14 def ignored_strategy_symbols [:Base, :ImportStatus] end |