Module: PagesCore::PoliciesHelper::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#inferred_policy_classObject



23
24
25
# File 'app/controllers/concerns/pages_core/policies_helper.rb', line 23

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

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



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

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