Module: Policies::Methods

Defined in:
lib/policies/methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
# File 'lib/policies/methods.rb', line 2

def self.included(base)
  base.send(:helper_method, :authorized?) if base.respond_to?(:helper_method)
end

Instance Method Details

#authorize(action = action_name, object) ⇒ Object



6
7
8
# File 'lib/policies/methods.rb', line 6

def authorize(action = action_name, object)
  raise Policies::UnauthorizedError unless authorized?(action, object)
end

#authorized?(action = action_name, object) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/policies/methods.rb', line 10

def authorized?(action = action_name, object)
  policy_class(object).new(current_user, current_role, object).public_send(action.to_s + '?')
end