Module: SafetyPatrol::Padrino::Helpers

Defined in:
lib/safety_patrol/padrino/helpers.rb

Instance Method Summary collapse

Instance Method Details

#can!(action, resource) ⇒ Object



13
14
15
16
17
# File 'lib/safety_patrol/padrino/helpers.rb', line 13

def can!(action, resource)
  raise "can! cannot be passed a block" if block_given?
  can_perform_action = can?(action, resource)
  raise SafetyPatrol::Padrino::SafteyViolation.new(safety_patrol_user, action.to_s, resource) unless can_perform_action
end

#can?(action, resource) {|can_perform_action| ... } ⇒ Boolean

Yields:

  • (can_perform_action)

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/safety_patrol/padrino/helpers.rb', line 7

def can?(action, resource, &block)
    can_perform_action = safety_patrol_user.send(("can_#{action.to_s}?").intern, resource)
    yield(can_perform_action) if block_given?
    can_perform_action
end

#safety_patrol_userObject



19
20
21
# File 'lib/safety_patrol/padrino/helpers.rb', line 19

def safety_patrol_user
  send(SafetyPatrol.configuration.user_method)
end