Class: Hyrax::WorkGenerator

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

Instance Method Summary collapse

Instance Method Details

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



17
18
19
20
21
22
23
# File 'lib/generators/hyrax/work/work_generator.rb', line 17

def banner
  if revoking?
    say_status("info", "DESTROYING WORK MODEL: #{class_name}", :blue)
  else
    say_status("info", "GENERATING WORK MODEL: #{class_name}", :blue)
  end
end

#create_actorObject



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

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

#create_actor_specObject



71
72
73
74
# File 'lib/generators/hyrax/work/work_generator.rb', line 71

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

#create_controllerObject



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

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

#create_controller_specObject



76
77
78
79
# File 'lib/generators/hyrax/work/work_generator.rb', line 76

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

#create_feature_specObject



81
82
83
84
# File 'lib/generators/hyrax/work/work_generator.rb', line 81

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

#create_formObject



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

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

#create_form_specObject



86
87
88
89
# File 'lib/generators/hyrax/work/work_generator.rb', line 86

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

#create_i18nObject



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

def create_i18n
  template('locale.en.yml.erb', File.join('config/locales/', class_path, "#{file_name}.en.yml"))
  template('locale.es.yml.erb', File.join('config/locales/', class_path, "#{file_name}.es.yml"))
  template('locale.zh.yml.erb', File.join('config/locales/', class_path, "#{file_name}.zh.yml"))
end

#create_modelObject



37
38
39
# File 'lib/generators/hyrax/work/work_generator.rb', line 37

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

#create_model_specObject



91
92
93
94
# File 'lib/generators/hyrax/work/work_generator.rb', line 91

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

#create_viewsObject



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

def create_views
  create_file File.join('app/views/hyrax', class_path, "#{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

#display_readmeObject



96
97
98
# File 'lib/generators/hyrax/work/work_generator.rb', line 96

def display_readme
  readme 'README' unless revoking?
end

#register_workObject

Inserts after the last registered work, or at the top of the config block



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/hyrax/work/work_generator.rb', line 49

def register_work
  config = 'config/initializers/hyrax.rb'
  lastmatch = nil
  in_root do
    File.open(config).each_line do |line|
      lastmatch = line if line =~ /config.register_curation_concern :(?!#{file_name})/
    end
    content = "  # Injected via `rails g hyrax:work #{class_name}`\n" \
              "  config.register_curation_concern #{registration_path_symbol}\n"
    anchor = lastmatch || "Hyrax.config do |config|\n"
    inject_into_file config, after: anchor do
      content
    end
  end
end