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



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

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



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

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
# 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)
  route route_block.result(binding) 
end

- (Object) add_views



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

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


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

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)



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

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

- (Object) full_interpreter_class (private)



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

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

- (Object) interpreter_class (private)



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

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

- (Object) model_controller (private)



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

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

- (Object) model_path_prefix (private)



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

def model_path_prefix
  table_name
end

- (Object) preview_url (private)



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

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

- (Object) table_name (private)



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

def table_name 
  model_name.tableize
end