Class: Bali::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/bali/foundations/rule/rule.rb

Overview

for internal use, representing one, single, atomic rule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_val, operation) ⇒ Rule

Returns a new instance of Rule.



14
15
16
17
18
# File 'lib/bali/foundations/rule/rule.rb', line 14

def initialize(auth_val, operation)
  self.auth_val = auth_val
  @operation = operation
  self
end

Instance Attribute Details

#auth_valObject

auth_val is either :can or :cannot



4
5
6
# File 'lib/bali/foundations/rule/rule.rb', line 4

def auth_val
  @auth_val
end

#deciderObject

if decider is defined, a rule is executed only if decider evaluates to true



10
11
12
# File 'lib/bali/foundations/rule/rule.rb', line 10

def decider
  @decider
end

#decider_typeObject

either unless or if



12
13
14
# File 'lib/bali/foundations/rule/rule.rb', line 12

def decider_type
  @decider_type
end

#operationObject (readonly)

what is the operation: create, update, delete, or any other



7
8
9
# File 'lib/bali/foundations/rule/rule.rb', line 7

def operation
  @operation
end

Instance Method Details

#cloneObject



20
21
22
23
24
25
26
# File 'lib/bali/foundations/rule/rule.rb', line 20

def clone
  cloned_rule = Bali::Rule.new(auth_val, operation)
  cloned_rule.decider = decider if decider
  cloned_rule.decider_type = decider_type if decider_type

  cloned_rule
end

#has_decider?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/bali/foundations/rule/rule.rb', line 52

def has_decider?
  self.decider.is_a?(Proc) && !self.decider_type.nil?
end

#is_discouragement?Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/bali/foundations/rule/rule.rb', line 47

def is_discouragement?
  # TODO: in version 3.0 remove :cant
  self.auth_val == :cannot || self.auth_val == :cant
end