Class: Dry::Logic::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/logic/rule.rb,
lib/dry/logic/rule/negation.rb

Direct Known Subclasses

Composite, Value

Defined Under Namespace

Classes: Attr, Check, Composite, Conjunction, Disjunction, Each, ExclusiveDisjunction, Implication, Key, Negation, Set, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate, options = {}) ⇒ Rule

Returns a new instance of Rule.



10
11
12
13
# File 'lib/dry/logic/rule.rb', line 10

def initialize(predicate, options = {})
  @predicate = predicate
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/dry/logic/rule.rb', line 8

def options
  @options
end

#predicateObject (readonly)

Returns the value of attribute predicate.



6
7
8
# File 'lib/dry/logic/rule.rb', line 6

def predicate
  @predicate
end

Instance Method Details

#and(other) ⇒ Object Also known as: &



23
24
25
# File 'lib/dry/logic/rule.rb', line 23

def and(other)
  Conjunction.new(self, other)
end

#curry(*args) ⇒ Object



51
52
53
# File 'lib/dry/logic/rule.rb', line 51

def curry(*args)
  self.class.new(predicate.curry(*args), options)
end

#each?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/dry/logic/rule.rb', line 55

def each?
  predicate.is_a?(Rule::Each)
end

#negationObject



43
44
45
# File 'lib/dry/logic/rule.rb', line 43

def negation
  Negation.new(self)
end

#new(predicate) ⇒ Object



47
48
49
# File 'lib/dry/logic/rule.rb', line 47

def new(predicate)
  self.class.new(predicate, options)
end

#or(other) ⇒ Object Also known as: |



28
29
30
# File 'lib/dry/logic/rule.rb', line 28

def or(other)
  Disjunction.new(self, other)
end

#predicate_idObject



15
16
17
# File 'lib/dry/logic/rule.rb', line 15

def predicate_id
  predicate.id
end

#then(other) ⇒ Object Also known as: >



38
39
40
# File 'lib/dry/logic/rule.rb', line 38

def then(other)
  Implication.new(self, other)
end

#typeObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/dry/logic/rule.rb', line 19

def type
  raise NotImplementedError
end

#xor(other) ⇒ Object Also known as: ^



33
34
35
# File 'lib/dry/logic/rule.rb', line 33

def xor(other)
  ExclusiveDisjunction.new(self, other)
end