class ActionBouncer::Allowance
Attributes
resource_sym[R]
Public Class Methods
new(resource_sym, options)
click to toggle source
# File lib/action_bouncer/allowance.rb, line 5 def initialize(resource_sym, options) @resource_sym, @options = resource_sym, options end
Public Instance Methods
allowed?(controller, action)
click to toggle source
# File lib/action_bouncer/allowance.rb, line 9 def allowed?(controller, action) resource = controller.send(@resource_sym) exception_action?(action) || (allowed_action?(action) && matches_resource_condition?(resource)) end
Private Instance Methods
allowed_action?(action)
click to toggle source
# File lib/action_bouncer/allowance.rb, line 17 def allowed_action?(action) allowed_actions.include?(action.to_sym) || allowed_actions.include?(:all) end
allowed_actions()
click to toggle source
# File lib/action_bouncer/allowance.rb, line 29 def allowed_actions Array.wrap(@options[:to]) end
conditions()
click to toggle source
# File lib/action_bouncer/allowance.rb, line 37 def conditions Array.wrap(@options[:if]) end
exception_action?(action)
click to toggle source
# File lib/action_bouncer/allowance.rb, line 21 def exception_action?(action) exception_actions.include?(action.to_sym) end
exception_actions()
click to toggle source
# File lib/action_bouncer/allowance.rb, line 33 def exception_actions Array.wrap(@options[:except]) end
matches_resource_condition?(resource)
click to toggle source
# File lib/action_bouncer/allowance.rb, line 25 def matches_resource_condition?(resource) conditions.any? { |condition| resource.send(condition).present? } end