class Fortress::ControllerInterface
Object to easily use the Mechanism
stored rules. It's a kind of helper class
@author zedtux
Attributes
instance[RW]
params[RW]
Public Class Methods
new(controller_instance)
click to toggle source
# File lib/fortress/controller_interface.rb, line 11 def initialize(controller_instance) self.instance = controller_instance end
Public Instance Methods
action_allowed_from_only?(name)
click to toggle source
# File lib/fortress/controller_interface.rb, line 71 def action_allowed_from_only?(name) Array(params[:only]).include?(name.to_sym) end
action_forbidden?(name)
click to toggle source
# File lib/fortress/controller_interface.rb, line 67 def action_forbidden?(name) Array(params[:except]).include?(name.to_sym) end
allow_action?(name)
click to toggle source
# File lib/fortress/controller_interface.rb, line 31 def allow_action?(name) return false if action_forbidden?(name.to_sym) if conditionnal_method_with_action?(name.to_sym) return call_allow_method == true end return true if action_allowed_from_only?(name.to_sym) allow_all? end
allow_all?()
click to toggle source
# File lib/fortress/controller_interface.rb, line 23 def allow_all? params[:all] == true end
allow_all_without_except?()
click to toggle source
# File lib/fortress/controller_interface.rb, line 27 def allow_all_without_except? allow_all? && params.key?(:except) == false end
allow_method?()
click to toggle source
# File lib/fortress/controller_interface.rb, line 43 def allow_method? params.key?(:if) && params[:if].key?(:method) end
blocked?()
click to toggle source
# File lib/fortress/controller_interface.rb, line 19 def blocked? params.nil? end
call_allow_method()
click to toggle source
# File lib/fortress/controller_interface.rb, line 52 def call_allow_method instance.send(params[:if][:method]) end
conditionally_allowed?(action_name)
click to toggle source
# File lib/fortress/controller_interface.rb, line 56 def conditionally_allowed?(action_name) return unless allow_method? return unless needs_to_check_action?(action_name.to_sym) call_allow_method end
conditionnal_method_with_action?(name)
click to toggle source
# File lib/fortress/controller_interface.rb, line 62 def conditionnal_method_with_action?(name) return false unless params.key?(:if) && params[:if].key?(:actions) return true if params[:if][:actions].include?(name) end
needs_to_check_action?(name)
click to toggle source
# File lib/fortress/controller_interface.rb, line 47 def needs_to_check_action?(name) params.key?(:if) && params[:if].key?(:actions) && Array(params[:if][:actions]).include?(name) end