Module: PagesCore::PoliciesHelper::ClassMethods

Defined in:
app/controllers/concerns/pages_core/policies_helper.rb

Instance Method Summary collapse

Instance Method Details

#inferred_policy_classObject


21
22
23
# File 'app/controllers/concerns/pages_core/policies_helper.rb', line 21

def inferred_policy_class
  const_get(name.demodulize.gsub(/Controller$/, "").singularize)
end

#require_authorization(object: nil, instance: nil) ⇒ Object


10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/concerns/pages_core/policies_helper.rb', line 10

def require_authorization(object: nil, instance: nil)
  object ||= inferred_policy_class

  before_action do |controller|
    instance_name = "@#{object.name.underscore}"
    record = instance || controller.instance_variable_get(instance_name)

    verify_policy_with_proc(controller, record || object)
  end
end