Class: Dry::Logic::Operations::Set

Inherits:
Abstract
  • Object
show all
Defined in:
lib/dry/logic/operations/set.rb

Instance Attribute Summary

Attributes inherited from Abstract

#options, #rules

Instance Method Summary collapse

Methods inherited from Abstract

#curry, #id, #initialize, #new, #to_ast, #with

Methods included from Dry::Logic::Operators

#and, #or, #then, #xor

Constructor Details

This class inherits a constructor from Dry::Logic::Operations::Abstract

Instance Method Details

#[](input) ⇒ Object



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

def [](input)
  rules.map { |rule| rule[input] }.all?
end

#ast(input = Undefined) ⇒ Object



27
28
29
# File 'lib/dry/logic/operations/set.rb', line 27

def ast(input = Undefined)
  [type, rules.map { |rule| rule.ast(input) }]
end

#call(input) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/dry/logic/operations/set.rb', line 14

def call(input)
  results = rules.map { |rule| rule.(input) }
  success = results.all?(&:success?)

  Result.new(success, id) do
    [type, results.select(&:failure?).map { |failure| failure.to_ast }]
  end
end

#to_sObject



31
32
33
# File 'lib/dry/logic/operations/set.rb', line 31

def to_s
  "#{type}(#{rules.map(&:to_s).join(', ')})"
end

#typeObject



10
11
12
# File 'lib/dry/logic/operations/set.rb', line 10

def type
  :set
end