Class: Miau::PolicyRun

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/miau/run.rb

Instance Method Summary collapse

Instance Method Details

#find_methods(policy, klass, action) ⇒ Object

return method klass and action are symbols Priority:

- method of <klass>Policy
- method of <klass>Policy specified by "miau action, method"
- method of ApplicationPolicy (independent of klass)
- method of ApplicationPolicy specified by "miau action, method"
- nil

returns method_name



20
21
22
23
24
25
26
27
# File 'lib/miau/run.rb', line 20

def find_methods(policy, klass, action)
  return action if policy.respond_to?(action)

  hsh = PolicyStorage.instance.policies[klass]
  return nil unless hsh

  hsh[action]
end

#raise_authorize(controller, action) ⇒ Object

Raises:



43
44
45
46
# File 'lib/miau/run.rb', line 43

def raise_authorize(controller, action)
  msg = "controller <#{controller}> action <#{action}>"
  raise NotAuthorizedError, msg
end

#raise_undef(policy, action) ⇒ Object

Raises:



38
39
40
41
# File 'lib/miau/run.rb', line 38

def raise_undef(policy, action)
  msg = "policy <#{policy}> action <#{action}>"
  raise NotDefinedError, msg
end

#runs(policy, actions) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/miau/run.rb', line 29

def runs(policy, actions)
  [actions].flatten.each { |action|
    raise_undef(policy, action) unless policy&.respond_to?(action)

    return false unless policy.send(action)
  }
  true
end