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

#has_decider?Boolean

Returns:

  • (Boolean)

Raises:



44
45
46
47
# File 'lib/bali/foundations/rule/rule.rb', line 44

def has_decider?
  raise Bali::DslError, "has decider but not sure if it is if or unless type decider" if self.decider.is_a?(Proc) && self.decider_type.nil?
  self.decider.is_a?(Proc)
end

#is_discouragement?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/bali/foundations/rule/rule.rb', line 39

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