Class: Blacklight::AccessControlsGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_access_controls_to_catalog_controllerObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/blacklight/access_controls_generator.rb', line 40

def add_access_controls_to_catalog_controller
  say_status('status', 'ADDING ACCESS CONTROLS TO CATALOG CONTROLLER', :yellow)

  string_to_insert = <<-EOS
  include Blacklight::AccessControls::Catalog

  # Apply the blacklight-access_controls
  before_filter :enforce_show_permissions, only: :show

  EOS

  insert_into_file 'app/controllers/catalog_controller.rb',
    string_to_insert, after: "include Blacklight::Catalog\n"
end

#add_access_controls_to_search_builderObject



31
32
33
34
35
36
37
38
# File 'lib/generators/blacklight/access_controls_generator.rb', line 31

def add_access_controls_to_search_builder
  say_status('status', 'ADDING ACCESS CONTROLS TO SEARCH BUILDERS', :yellow)
  options[:search_builders].each do |file_path|
    insert_into_file file_path,
      "  include Blacklight::AccessControls::Enforcement\n\n",
      after: "include Blacklight::Solr::SearchBuilderBehavior\n"
  end
end

#add_access_controls_to_userObject



24
25
26
27
28
29
# File 'lib/generators/blacklight/access_controls_generator.rb', line 24

def add_access_controls_to_user
  say_status('status', 'ADDING ACCESS CONTROLS TO USER MODEL', :yellow)
  insert_into_file File.join('app','models', "#{options[:user_model].underscore}.rb"),
    "  include Blacklight::AccessControls::User\n\n",
    after: "include Blacklight::User\n"
end

#add_cancan_abilityObject



55
56
57
58
# File 'lib/generators/blacklight/access_controls_generator.rb', line 55

def add_cancan_ability
  say_status('status', 'ADDING CANCAN ABILITY', :yellow)
  copy_file 'ability.rb', 'app/models/ability.rb'
end

#add_configurationObject



60
61
62
63
# File 'lib/generators/blacklight/access_controls_generator.rb', line 60

def add_configuration
  say_status('status', 'ADDING BLACKLIGHT ACCESS CONTROLS CONFIGURATION', :yellow)
  copy_file 'blacklight_access_controls.rb', 'config/initializers/blacklight_access_controls.rb'
end