Class: CurationConcerns::Install

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/curation_concerns/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_helperObject



92
93
94
# File 'lib/generators/curation_concerns/install_generator.rb', line 92

def add_helper
  copy_file 'curation_concerns_helper.rb', 'app/helpers/curation_concerns_helper.rb'
end

#assetsObject



88
89
90
# File 'lib/generators/curation_concerns/install_generator.rb', line 88

def assets
  generate 'curation_concerns:assets' unless options[:'skip-assets']
end

#catalog_controllerObject



71
72
73
# File 'lib/generators/curation_concerns/install_generator.rb', line 71

def catalog_controller
  copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
end

#inject_abilityObject



64
65
66
67
68
69
# File 'lib/generators/curation_concerns/install_generator.rb', line 64

def inject_ability
  inject_into_file 'app/models/ability.rb', after: /Hydra::Ability\s*\n/ do
    "  include CurationConcerns::Ability\n"\
    "  self.ability_logic += [:everyone_can_create_curation_concerns]\n\n"
  end
end

#inject_application_controller_behaviorObject



32
33
34
35
36
37
# File 'lib/generators/curation_concerns/install_generator.rb', line 32

def inject_application_controller_behavior
  inject_into_file 'app/controllers/application_controller.rb', after: /Hydra::Controller::ControllerBehavior\s*\n/ do
    "\n  # Adds CurationConcerns behaviors to the application controller.\n" \
    "  include CurationConcerns::ApplicationControllerBehavior\n"
  end
end

#inject_routesObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generators/curation_concerns/install_generator.rb', line 50

def inject_routes
  # Remove root route that was added by blacklight generator
  gsub_file 'config/routes.rb', /root (:to =>|to:) "catalog#index"/, ''

  inject_into_file 'config/routes.rb', after: /devise_for :users\s*\n/ do
    "  mount CurationConcerns::Engine, at: '/'\n"\
    "  resources :welcome, only: 'index'\n"\
    "  root 'welcome#index'\n"\
    "  curation_concerns_collections\n"\
    "  curation_concerns_basic_routes\n"\
    "  curation_concerns_embargo_management\n"\
  end
end

#inject_solr_document_behaviorObject

Add behaviors to the SolrDocument model



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/curation_concerns/install_generator.rb', line 76

def inject_solr_document_behavior
  file_path = 'app/models/solr_document.rb'
  if File.exist?(file_path)
    inject_into_file file_path, after: /include Blacklight::Solr::Document.*$/ do
      "\n  # Adds CurationConcerns behaviors to the SolrDocument.\n" \
        "  include CurationConcerns::SolrDocumentBehavior\n"
    end
  else
    puts "     \e[31mFailure\e[0m  CurationConcerns requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist."
  end
end

#insert_builderObject



44
45
46
47
48
# File 'lib/generators/curation_concerns/install_generator.rb', line 44

def insert_builder
  insert_into_file 'app/models/search_builder.rb', after: /include Hydra::AccessControlsEnforcement/ do
    "\n  include CurationConcerns::SearchFilters\n"
  end
end

#replace_blacklight_layoutObject



39
40
41
42
# File 'lib/generators/curation_concerns/install_generator.rb', line 39

def replace_blacklight_layout
  gsub_file 'app/controllers/application_controller.rb', /layout 'blacklight'/,
            "include CurationConcerns::ThemedLayoutController\n  with_themed_layout '1_column'\n"
end

#resource_types_configObject



100
101
102
# File 'lib/generators/curation_concerns/install_generator.rb', line 100

def resource_types_config
  copy_file "config/authorities/resource_types.yml", "config/authorities/resource_types.yml"
end

#rights_configObject



96
97
98
# File 'lib/generators/curation_concerns/install_generator.rb', line 96

def rights_config
  copy_file "config/authorities/rights.yml", "config/authorities/rights.yml"
end

#run_required_generatorsObject



23
24
25
26
27
28
29
30
# File 'lib/generators/curation_concerns/install_generator.rb', line 23

def run_required_generators
  say_status('warning', '[CurationConcerns] GENERATING BLACKLIGHT', :yellow)
  generate 'blacklight:install --devise'
  say_status('warning', '[CurationConcerns] GENERATING HYDRA-HEAD', :yellow)
  generate 'hydra:head -f'
  say_status('warning', '[CurationConcerns] GENERATING CURATION_CONCERNS MODELS', :yellow)
  generate "curation_concerns:models#{options[:force] ? ' -f' : ''}"
end

#simple_form_initializersObject



104
105
106
107
108
109
# File 'lib/generators/curation_concerns/install_generator.rb', line 104

def simple_form_initializers
  copy_file 'config/initializers/simple_form.rb',
            'config/initializers/simple_form.rb'
  copy_file 'config/initializers/simple_form_bootstrap.rb',
            'config/initializers/simple_form_bootstrap.rb'
end