Class: GeoWorks::Install

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



6
7
8
# File 'lib/generators/geo_works/install_generator.rb', line 6

def class_name
  @class_name
end

Instance Method Details

#copy_hyrax_derivate_path_monkey_patchObject



59
60
61
62
# File 'lib/generators/geo_works/install_generator.rb', line 59

def copy_hyrax_derivate_path_monkey_patch
  file_path = 'config/initializers/hyrax_derivative_path_monkey_patch.rb'
  copy_file file_path, file_path
end

#file_set_presenterObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/generators/geo_works/install_generator.rb', line 83

def file_set_presenter
  file_path = 'app/presenters/file_set_presenter.rb'
  if File.exist?(file_path)
    inject_into_file file_path, after: /class FileSetPresenter.*$/ do
      "\n  # GeoWorks FileSetPresenter behavior\n" \
        "  include ::GeoWorks::FileSetPresenterBehavior\n"
    end
  else
    copy_file 'presenters/file_set_presenter.rb', file_path
  end
end

#inject_derivative_service_into_hyrax_initializerObject



125
126
127
128
129
130
131
# File 'lib/generators/geo_works/install_generator.rb', line 125

def inject_derivative_service_into_hyrax_initializer
  file_path = 'config/initializers/hyrax.rb'
  append_to_file file_path do
    "# Add derivative service for GeoWorks\n" \
      "Hyrax::DerivativeService.services = [GeoWorks::FileSetDerivativesService] + Hyrax::DerivativeService.services\n"
  end
end

#inject_into_file_setObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/generators/geo_works/install_generator.rb', line 71

def inject_into_file_set
  file_path = 'app/models/file_set.rb'
  if File.exist?(file_path)
    inject_into_file file_path, after: /include ::Hyrax::FileSetBehavior.*$/ do
      "\n  # GeoWorks behavior to FileSet.\n" \
        "  include ::GeoWorks::GeoFileSetBehavior\n"
    end
  else
    copy_file 'models/file_set.rb', file_path
  end
end

#inject_solr_document_behaviorObject

Add behaviors to the SolrDocument model



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/generators/geo_works/install_generator.rb', line 96

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 GeoWorks behaviors to the SolrDocument.\n" \
        "  include GeoWorks::SolrDocumentBehavior\n"
    end
  else
    Rails.logger.info "     \e[31mFailure\e[0m  GeoWorks requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist."
  end
end

#install_abilityObject



14
15
16
17
18
# File 'lib/generators/geo_works/install_generator.rb', line 14

def install_ability
  inject_into_file 'app/models/ability.rb', after: "include Hyrax::Ability\n" do
    "  include GeoWorks::Ability\n"
  end
end

#install_authoritiesObject



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

def install_authorities
  %w(metadata image vector raster).each do |type|
    file_path = "config/authorities/#{type}_formats.yml"
    copy_file file_path, file_path
  end
end

#install_css_assetsObject



118
119
120
121
122
123
# File 'lib/generators/geo_works/install_generator.rb', line 118

def install_css_assets
  file_path = 'app/assets/stylesheets/application.css'
  inject_into_file file_path, before: /\*= require_tree \..*$/ do
    "*= require geo_works/application\n "
  end
end

#install_file_sets_controllerObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/geo_works/install_generator.rb', line 47

def install_file_sets_controller
  file_path = 'app/controllers/hyrax/file_sets_controller.rb'
  if File.exist?(file_path)
    inject_into_file file_path, after: /include Hyrax::FileSetsControllerBehavior.*$/ do
      "\n    include GeoConcerns::FileSetsControllerBehavior\n" \
        "    include GeoConcerns::EventsBehavior\n"
    end
  else
    copy_file 'controllers/hyrax/file_sets_controller.rb', file_path
  end
end

#install_image_workObject



41
42
43
44
45
# File 'lib/generators/geo_works/install_generator.rb', line 41

def install_image_work
  @class_name = 'ImageWork'
  install_work
  install_specs
end

#install_js_assetsObject



108
109
110
111
112
113
114
115
116
# File 'lib/generators/geo_works/install_generator.rb', line 108

def install_js_assets
  file_path = 'app/assets/javascripts/application.js'
  inject_into_file file_path, before: %r{\/\/= require_tree \..*$} do
    "//= require geo_works/application\n" \
    "//= require hyrax\n" \
    "// Require es6 modules after almond is loaded in hyrax.\n" \
    "//= require geo_works/es6-modules\n"
  end
end

#install_raster_workObject



29
30
31
32
33
# File 'lib/generators/geo_works/install_generator.rb', line 29

def install_raster_work
  @class_name = 'RasterWork'
  install_work
  install_specs
end

#install_routesObject



8
9
10
11
12
# File 'lib/generators/geo_works/install_generator.rb', line 8

def install_routes
  inject_into_file 'config/routes.rb', after: /curation_concerns_embargo_management\s*\n/ do
    "  mount GeoWorks::Engine => '/'\n"\
  end
end

#install_vector_workObject



35
36
37
38
39
# File 'lib/generators/geo_works/install_generator.rb', line 35

def install_vector_work
  @class_name = 'VectorWork'
  install_work
  install_specs
end

#register_workObject



20
21
22
23
24
25
26
27
# File 'lib/generators/geo_works/install_generator.rb', line 20

def register_work
  inject_into_file 'config/initializers/hyrax.rb', after: "Hyrax.config do |config|\n" do
    "  # Injected via `rails g geo_works:install`\n" \
      "  config.register_curation_concern :vector_work\n" \
      "  config.register_curation_concern :raster_work\n" \
      "  config.register_curation_concern :image_work\n"
  end
end