Class: Sufia::WorkGenerator

Inherits:
CurationConcerns::WorkGenerator
  • Object
show all
Defined in:
lib/generators/sufia/work_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_modelObject



13
14
15
16
# File 'lib/generators/sufia/work_generator.rb', line 13

def create_model
  say_status("info", "GENERATING WORK MODEL", :blue)
  super
end

#inject_sufia_formObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/sufia/work_generator.rb', line 32

def inject_sufia_form
  file_path = "app/forms/curation_concerns/#{file_name}_form.rb"
  if File.exist?(file_path)
    gsub_file file_path, /CurationConcerns::Forms::WorkForm/, "Sufia::Forms::WorkForm"
    inject_into_file file_path, after: /model_class = ::.*$/ do
      "\n    self.terms += [:resource_type]\n"
    end
  else
    puts "     \e[31mFailure\e[0m  Sufia requires a #{class_name}Form object. This generator assumes that the model is defined in the file #{file_path}, which does not exist."
  end
end

#inject_sufia_work_behaviorObject



25
26
27
28
29
30
# File 'lib/generators/sufia/work_generator.rb', line 25

def inject_sufia_work_behavior
  insert_into_file "app/models/#{name.underscore}.rb", after: 'include ::CurationConcerns::BasicMetadata' do
    "\n  include Sufia::WorkBehavior" \
    "\n  self.human_readable_type = 'Work'"
  end
end

#inject_sufia_work_controller_behaviorObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/sufia/work_generator.rb', line 44

def inject_sufia_work_controller_behavior
  file_path = "app/controllers/curation_concerns/#{plural_file_name}_controller.rb"
  if File.exist?(file_path)
    inject_into_file file_path, after: /include CurationConcerns::CurationConcernController/ do
      "\n    # Adds Sufia behaviors to the controller.\n" \
        "    include Sufia::WorksControllerBehavior\n"
    end
  else
    puts "     \e[31mFailure\e[0m  Sufia requires a #{controller_class_name} object. This generator assumes that the model is defined in the file #{file_path}, which does not exist."
  end
end

#register_workObject



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

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