Class: TaxonWorks::BatchLoadGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- TaxonWorks::BatchLoadGenerator
- Defined in:
- lib/generators/taxon_works/batch_load/batch_load_generator.rb
Instance Method Summary collapse
- #add_batch_load_index ⇒ Object
- #add_controller_stubs ⇒ Object
- #add_routes ⇒ Object
- #add_views ⇒ Object
- #cookie_name ⇒ Object private
-
#create_interpreter ⇒ Object
Fail if existing batch_loader exists.
- #create_url ⇒ Object private
- #full_interpreter_class ⇒ Object private
- #interpreter_class ⇒ Object private
- #model_controller ⇒ Object private
- #model_path_prefix ⇒ Object private
- #preview_url ⇒ Object private
- #table_name ⇒ Object private
Instance Method Details
#add_batch_load_index ⇒ Object
27 28 29 30 31 32 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 27 def add_batch_load_index f = "app/views/#{model_path_prefix}/batch_load.html.erb" create_file f index_block = ERB.new(File.open(find_in_source_paths('index.tt')).read) append_to_file f, index_block.result(binding) end |
#add_controller_stubs ⇒ Object
40 41 42 43 44 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 40 def add_controller_stubs f = "app/controllers/#{model_path_prefix}_controller.rb" actions_block = ERB.new(File.open(find_in_source_paths('actions.tt')).read) inject_into_class f, model_controller, actions_block.result(binding) end |
#add_routes ⇒ Object
20 21 22 23 24 25 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 20 def add_routes # To insert rows in order use a template, and pass it to routes route_block = ERB.new(File.open(find_in_source_paths('routes.tt')).read) prepend_to_file('config/routes/data.rb', route_block.result(binding)) # route route_block.result(binding) end |
#add_views ⇒ Object
34 35 36 37 38 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 34 def add_views %w{_batch_load _form create preview}.each do |t| template "views/#{t}", "app/views/#{model_path_prefix}/batch_load/#{batch_loader_name}/#{t}.html.erb" end end |
#cookie_name ⇒ Object (private)
73 74 75 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 73 def "#{batch_loader_name}_batch_load_#{table_name}_md5" end |
#create_interpreter ⇒ Object
Fail if existing batch_loader exists
16 17 18 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 16 def create_interpreter template 'interpreter', "lib/batch_load/import/#{table_name}/#{batch_loader_name}_interpreter.rb" end |
#create_url ⇒ Object (private)
85 86 87 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 85 def create_url "create_#{batch_loader_name}_batch_load_#{table_name}_path" end |
#full_interpreter_class ⇒ Object (private)
61 62 63 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 61 def full_interpreter_class "BatchLoad::Import::#{model_name.pluralize}::#{interpreter_class}" end |
#interpreter_class ⇒ Object (private)
57 58 59 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 57 def interpreter_class "#{batch_loader_name.split('_').map(&:capitalize).join('')}Interpreter" end |
#model_controller ⇒ Object (private)
77 78 79 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 77 def model_controller "#{model_name.pluralize}Controller" end |
#model_path_prefix ⇒ Object (private)
65 66 67 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 65 def model_path_prefix table_name end |
#preview_url ⇒ Object (private)
81 82 83 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 81 def preview_url "preview_#{batch_loader_name}_batch_load_#{table_name}_path" end |
#table_name ⇒ Object (private)
69 70 71 |
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 69 def table_name model_name.tableize end |