Class: Dry::Logic::Rule::Key

Inherits:
Value show all
Defined in:
lib/dry/logic/rule/key.rb

Direct Known Subclasses

Attr

Instance Attribute Summary collapse

Attributes inherited from Dry::Logic::Rule

#options, #predicate

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#apply, #call

Methods inherited from Dry::Logic::Rule

#and, #curry, #each?, #negation, #new, #or, #predicate_id, #then, #xor

Constructor Details

#initialize(predicate, options) ⇒ Key

Returns a new instance of Key.



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

def initialize(predicate, options)
  super
  @name = options[:name]
  @evaluator = options[:evaluator]
end

Instance Attribute Details

#evaluatorObject (readonly)

Returns the value of attribute evaluator.



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

def evaluator
  @evaluator
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.evaluator(options) ⇒ Object



13
14
15
# File 'lib/dry/logic/rule/key.rb', line 13

def self.evaluator(options)
  Evaluator::Key.new(options.fetch(:name))
end

.new(predicate, options) ⇒ Object



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

def self.new(predicate, options)
  name = options.fetch(:name)
  super(predicate, evaluator: evaluator(options), name: name)
end

Instance Method Details

#evaluate(input) ⇒ Object



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

def evaluate(input)
  evaluator[input]
end

#to_astObject



31
32
33
# File 'lib/dry/logic/rule/key.rb', line 31

def to_ast
  [type, [name, predicate.to_ast]]
end

#typeObject



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

def type
  :key
end