Class: Taxonworks::BatchLoadGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/taxonworks/batch_load/batch_load_generator.rb

Overview

Generate new TaxonWorks batch loaders

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_batch_load_index



26
27
28
29
30
31
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 26

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

- (Object) add_controller_stubs



39
40
41
42
43
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 39

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

- (Object) add_routes



19
20
21
22
23
24
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 19

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

- (Object) add_views



33
34
35
36
37
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 33

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


72
73
74
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 72

def cookie_name
  "#{batch_loader_name}_batch_load_#{table_name}_md5"
end

- (Object) create_interpreter

Fail if existing batch_loader exists



15
16
17
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 15

def create_interpreter 
  template 'interpreter', "lib/batch_load/import/#{table_name}/#{batch_loader_name}_interpreter.rb"
end

- (Object) create_url (private)



84
85
86
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 84

def create_url
  "create_#{batch_loader_name}_batch_load_#{table_name}_path"  
end

- (Object) full_interpreter_class (private)



60
61
62
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 60

def full_interpreter_class
  "BatchLoad::Import::#{model_name.pluralize}::#{interpreter_class}"
end

- (Object) interpreter_class (private)



56
57
58
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 56

def interpreter_class
  "#{batch_loader_name.split('_').map(&:capitalize).join('')}Interpreter"
end

- (Object) model_controller (private)



76
77
78
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 76

def model_controller
  "#{model_name.pluralize}Controller"
end

- (Object) model_path_prefix (private)



64
65
66
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 64

def model_path_prefix
  table_name
end

- (Object) preview_url (private)



80
81
82
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 80

def preview_url
  "preview_#{batch_loader_name}_batch_load_#{table_name}_path"  
end

- (Object) table_name (private)



68
69
70
# File 'lib/generators/taxonworks/batch_load/batch_load_generator.rb', line 68

def table_name 
  model_name.tableize
end