Class: TaxonWorks::BatchLoadGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_batch_load_indexObject



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_stubsObject



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_routesObject



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_viewsObject



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


73
74
75
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 73

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

#create_interpreterObject

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_urlObject (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_classObject (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_classObject (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_controllerObject (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_prefixObject (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_urlObject (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_nameObject (private)



69
70
71
# File 'lib/generators/taxon_works/batch_load/batch_load_generator.rb', line 69

def table_name 
  model_name.tableize
end