Class: CurationConcerns::WorkGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/curation_concerns/work/work_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_actorObject



57
58
59
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 57

def create_actor
  template('actor.rb.erb', "app/actors/curation_concerns/actors/#{file_name}_actor.rb")
end

#create_actor_specObject



38
39
40
41
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 38

def create_actor_spec
  return unless rspec_installed?
  template('actor_spec.rb.erb', "spec/actors/curation_concerns/actors/#{file_name}_actor_spec.rb")
end

#create_controllerObject



53
54
55
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 53

def create_controller
  template('controller.rb.erb', "app/controllers/curation_concerns/#{plural_file_name}_controller.rb")
end

#create_controller_specObject



33
34
35
36
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 33

def create_controller_spec
  return unless rspec_installed?
  template('controller_spec.rb.erb', "spec/controllers/curation_concerns/#{plural_file_name}_controller_spec.rb")
end

#create_feature_specObject



48
49
50
51
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 48

def create_feature_spec
  return unless rspec_installed?
  template('feature_spec.rb.erb', "spec/features/create_#{file_name}_spec.rb")
end

#create_formObject



61
62
63
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 61

def create_form
  template('form.rb.erb', "app/forms/curation_concerns/#{file_name}_form.rb")
end

#create_form_specObject



43
44
45
46
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 43

def create_form_spec
  return unless rspec_installed?
  template('form_spec.rb.erb', "spec/forms/curation_concerns/#{file_name}_form_spec.rb")
end

#create_modelObject



29
30
31
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 29

def create_model
  template('model.rb.erb', "app/models/#{file_name}.rb")
end

#create_model_specObject

Why all of these antics with defining individual methods? Because I want the output of CurationConcerns::WorkGenerator to include all the processed files.



24
25
26
27
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 24

def create_model_spec
  return unless rspec_installed?
  template 'model_spec.rb.erb', "spec/models/#{file_name}_spec.rb"
end

#create_readmeObject



79
80
81
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 79

def create_readme
  readme 'README'
end

#create_viewsObject



72
73
74
75
76
77
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 72

def create_views
  create_file "app/views/curation_concerns/#{plural_file_name}/_#{file_name}.html.erb" do
    "<%# This is a search result view %>\n" \
    "<%= render 'catalog/document', document: #{file_name}, document_counter: #{file_name}_counter  %>\n"
  end
end

#register_workObject



65
66
67
68
69
70
# File 'lib/generators/curation_concerns/work/work_generator.rb', line 65

def register_work
  inject_into_file 'config/initializers/curation_concerns.rb', after: "CurationConcerns.configure do |config|\n" do
    "  # Injected via `rails g curation_concerns:work #{class_name}`\n" \
    "  config.register_curation_concern :#{file_name}\n"
  end
end