Class: Fortress::ControllerInterface
- Inherits:
-
Object
- Object
- Fortress::ControllerInterface
- Defined in:
- lib/fortress/controller_interface.rb
Overview
Object to easily use the Mechanism stored rules. It’s a kind of helper class
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #action_allowed_from_only?(name) ⇒ Boolean
- #action_forbidden?(name) ⇒ Boolean
- #allow_action?(name) ⇒ Boolean
- #allow_all? ⇒ Boolean
- #allow_all_without_except? ⇒ Boolean
- #allow_method? ⇒ Boolean
- #blocked? ⇒ Boolean
- #call_allow_method ⇒ Object
- #conditionally_allowed?(action_name) ⇒ Boolean
- #conditionnal_method_with_action?(name) ⇒ Boolean
-
#initialize(controller_instance) ⇒ ControllerInterface
constructor
A new instance of ControllerInterface.
- #needs_to_check_action?(name) ⇒ Boolean
Constructor Details
#initialize(controller_instance) ⇒ ControllerInterface
Returns a new instance of ControllerInterface.
11 12 13 |
# File 'lib/fortress/controller_interface.rb', line 11 def initialize(controller_instance) self.instance = controller_instance end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
9 10 11 |
# File 'lib/fortress/controller_interface.rb', line 9 def instance @instance end |
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/fortress/controller_interface.rb', line 9 def params @params end |
Instance Method Details
#action_allowed_from_only?(name) ⇒ Boolean
71 72 73 |
# 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) ⇒ Boolean
67 68 69 |
# File 'lib/fortress/controller_interface.rb', line 67 def action_forbidden?(name) Array(params[:except]).include?(name.to_sym) end |
#allow_action?(name) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 |
# 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? ⇒ Boolean
23 24 25 |
# File 'lib/fortress/controller_interface.rb', line 23 def allow_all? params[:all] == true end |
#allow_all_without_except? ⇒ Boolean
27 28 29 |
# File 'lib/fortress/controller_interface.rb', line 27 def allow_all_without_except? allow_all? && params.key?(:except) == false end |
#allow_method? ⇒ Boolean
43 44 45 |
# File 'lib/fortress/controller_interface.rb', line 43 def allow_method? params.key?(:if) && params[:if].key?(:method) end |
#blocked? ⇒ Boolean
19 20 21 |
# File 'lib/fortress/controller_interface.rb', line 19 def blocked? params.nil? end |
#call_allow_method ⇒ Object
52 53 54 |
# File 'lib/fortress/controller_interface.rb', line 52 def call_allow_method instance.send(params[:if][:method]) end |
#conditionally_allowed?(action_name) ⇒ Boolean
56 57 58 59 60 |
# 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) ⇒ Boolean
62 63 64 65 |
# 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) ⇒ Boolean
47 48 49 50 |
# 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 |