Class: Acl9::Dsl::Base

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

Direct Known Subclasses

Generators::BaseGenerator

Constant Summary collapse

VALID_PREPOSITIONS =
%w(of for in on at by).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#allowsObject (readonly)

Returns the value of attribute allows.



4
5
6
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 4

def allows
  @allows
end

#denysObject (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_expressionObject 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_actionObject



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