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/#{name}/#{t}.html.erb"
  end
end

- (Object) batch_load_name (private)



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

def batch_load_name
  name.capitalize.humanize
end


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

def cookie_name
  batch_load_name + '_' + model_path_prefix + '_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/#{model_path_prefix}/#{name}_interpreter.rb"
end

- (Object) create_url (private)



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

def create_url
  "create_#{name}_batch_load_#{model_path_prefix}"  
end

- (Object) interpreter_class (private)



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

def interpreter_class
  "BatchLoad::Import::#{model_name.pluralize}::#{name.classify}Interpreter"
end

- (Object) model_controller (private)



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

def model_controller
  "#{model_name}sController"
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 
  "#{model_name.tableize}"
end

- (Object) preview_url (private)



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

def preview_url
  "preview_#{name}_batch_load_#{model_path_prefix}_path"  
end