Module: Shaf::Helpers

Defined in:
lib/shaf/extensions/log.rb,
lib/shaf/extensions/authorize.rb

Instance Method Summary collapse

Instance Method Details

#authorize(action, resource = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/shaf/extensions/authorize.rb', line 21

def authorize(action, resource = nil)
  policy = policy(resource)
  raise Authorize::NoPolicyError unless policy

  method = __method_for(action)
  return policy.public_send(method) if policy.respond_to? method

  raise Authorize::MissingPolicyAction,
    "#{policy.class} does not implement method #{method}"
end

#authorize!(action, resource = nil) ⇒ Object



32
33
34
# File 'lib/shaf/extensions/authorize.rb', line 32

def authorize!(action, resource = nil)
  authorize(action, resource) or raise Authorize::PolicyViolationError
end

#logObject



15
16
17
# File 'lib/shaf/extensions/log.rb', line 15

def log
  self.class.log
end