Class: Bulkrax::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_abilityObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/generators/bulkrax/install_generator.rb', line 58

def add_ability
  file = 'app/models/ability.rb'
  file_text = File.read(file)
  import_line = 'def can_import_works?'
  export_line = 'def can_export_works?'
  unless file_text.include?(import_line)
    insert_into_file file, before: /^end/ do
      "  def can_import_works?\n    can_create_any_work?\n  end"
    end
  end

  # rubocop:disable Style/GuardClause
  unless file_text.include?(export_line)
    insert_into_file file, before: /^end/ do
      "  def can_export_works?\n    can_create_any_work?\n  end"
    end
  end
  # rubocop:enable Style/GuardClause
end

#add_cssObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/generators/bulkrax/install_generator.rb', line 78

def add_css
  ['css', 'scss', 'sass'].map do |ext|
    file = "app/assets/stylesheets/application.#{ext}"
    next unless File.exist?(file)

    file_text = File.read(file)
    css = "*= require 'bulkrax/application'"
    next if file_text.include?(css)

    insert_into_file file, before: /\s\*= require_self/ do
      "\s#{css}\n"
    end
  end
end

#add_javascriptsObject



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

def add_javascripts
  file = 'app/assets/javascripts/application.js'
  file_text = File.read(file)
  js = '//= require bulkrax/application'

  return if file_text.include?(js)
  insert_into_file file, before: /\/\/= require_tree ./ do
    "#{js}\n"
  end
end

#add_removed_imageObject



97
98
99
# File 'lib/generators/bulkrax/install_generator.rb', line 97

def add_removed_image
  copy_file 'app/assets/images/bulkrax/removed.png', 'app/assets/images/bulkrax/removed.png'
end

#add_to_gemfileObject



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

def add_to_gemfile
  gem 'bulkrax'

  Bundler.with_clean_env do
    run "bundle install"
  end
end


8
9
10
# File 'lib/generators/bulkrax/install_generator.rb', line 8

def banner
  say_status("info", "Generating Bulkrax installation", :blue)
end

#create_bulkrax_apiObject



35
36
37
# File 'lib/generators/bulkrax/install_generator.rb', line 35

def create_bulkrax_api
  copy_file 'config/bulkrax_api.yml', 'config/bulkrax_api.yml'
end

#create_cmd_scriptObject



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

def create_cmd_script
  copy_file 'bin/importer', 'bin/importer'
end

#create_configObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/bulkrax/install_generator.rb', line 24

def create_config
  copy_file 'config/initializers/bulkrax.rb', 'config/initializers/bulkrax.rb'

  hyrax = "\n# set bulkrax default work type to first curation_concern if it isn't already set\nif Bulkrax.default_work_type.blank?\n  Bulkrax.default_work_type = Hyrax.config.curation_concerns.first.to_s\nend\n"

  return if File.read('config/initializers/hyrax.rb').include?(hyrax)
  append_to_file 'config/initializers/hyrax.rb' do
    hyrax
  end
end

#create_local_processingObject



43
44
45
# File 'lib/generators/bulkrax/install_generator.rb', line 43

def create_local_processing
  copy_file 'app/models/concerns/bulkrax/has_local_processing.rb', 'app/models/concerns/bulkrax/has_local_processing.rb'
end

#display_readmeObject



93
94
95
# File 'lib/generators/bulkrax/install_generator.rb', line 93

def display_readme
  readme 'README'
end

#mount_routeObject



20
21
22
# File 'lib/generators/bulkrax/install_generator.rb', line 20

def mount_route
  route "mount Bulkrax::Engine, at: '/'"
end