Class: Acl9::Dsl::Base
- Inherits:
-
Object
- Object
- Acl9::Dsl::Base
- Defined in:
- lib/acl9/controller_extensions/dsl_base.rb
Direct Known Subclasses
Constant Summary collapse
- VALID_PREPOSITIONS =
%w(of for in on at by).freeze
Instance Attribute Summary collapse
-
#allows ⇒ Object
readonly
Returns the value of attribute allows.
-
#denys ⇒ Object
readonly
Returns the value of attribute denys.
Instance Method Summary collapse
- #acl_block!(&acl_block) ⇒ Object
- #allowance_expression ⇒ Object (also: #to_s)
- #default_action ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 |
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 6 def initialize(*args) @default_action = nil @allows = [] @denys = [] @original_args = args end |
Instance Attribute Details
#allows ⇒ Object (readonly)
Returns the value of attribute allows.
4 5 6 |
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 4 def allows @allows end |
#denys ⇒ Object (readonly)
Returns the value of attribute denys.
4 5 6 |
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 4 def denys @denys end |
Instance Method Details
#acl_block!(&acl_block) ⇒ Object
15 16 17 |
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 15 def acl_block!(&acl_block) instance_eval(&acl_block) end |
#allowance_expression ⇒ Object Also known as: to_s
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 23 def allowance_expression allowed_expr = if @allows.size > 0 @allows.map { |clause| "(#{clause})" }.join(' || ') else "false" end not_denied_expr = if @denys.size > 0 @denys.map { |clause| "!(#{clause})" }.join(' && ') else "true" end [allowed_expr, not_denied_expr]. map { |expr| "(#{expr})" }. join(default_action == :deny ? ' && ' : ' || ') end |
#default_action ⇒ Object
19 20 21 |
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 19 def default_action if @default_action.nil? then :deny else @default_action end end |