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

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(*args)

Returns a new instance of Base



6
7
8
9
10
11
# 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

- (Object) allows (readonly)

Returns the value of attribute allows



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

def allows
  @allows
end

- (Object) denys (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

- (Object) acl_block!(&acl_block)



13
14
15
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 13

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

- (Object) allowance_expression Also known as: to_s



21
22
23
24
25
26
27
28
# File 'lib/acl9/controller_extensions/dsl_base.rb', line 21

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

- (Object) default_action



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

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