Class: Acl9::Dsl::Base

Inherits:
Object
  • Object
show all
Includes:
Prepositions
Defined in:
lib/acl9/controller_extensions/dsl_base.rb

Direct Known Subclasses

Generators::BaseGenerator

Constant Summary

Constants included from Prepositions

Prepositions::VALID_PREPOSITIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Prepositions

#_by_preposition

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.


10
11
12
13
14
15
16
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 10

def initialize(*args)
  @default_action = nil
  @allows = []
  @denys  = []
  @original_args = args
  @action_clause = nil
end

Instance Attribute Details

#allowsObject (readonly)

Returns the value of attribute allows


8
9
10
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 8

def allows
  @allows
end

#denysObject (readonly)

Returns the value of attribute denys


8
9
10
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 8

def denys
  @denys
end

Instance Method Details

#acl_block!(&acl_block) ⇒ Object


18
19
20
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 18

def acl_block!(&acl_block)
  instance_eval(&acl_block)
end

#allowance_expressionObject Also known as: to_s


26
27
28
29
30
31
32
33
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 26

def allowance_expression
  allowed_expr    = @allows.any?  ? @allows.map { |clause| "(#{clause})" }.join(' || ') : 'false'
  not_denied_expr = @denys.any?   ? @denys.map { |clause| "!(#{clause})" }.join(' && ') : 'true'

  [allowed_expr, not_denied_expr].
    map { |expr| "(#{expr})" }.
    join(default_action == :deny ? ' && ' : ' || ')
end

#default_actionObject


22
23
24
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 22

def default_action
  @default_action.nil? ? :deny : @default_action
end