Sha256: 3b1ea1f43682a1c7ab66785dbcd65e20c19e4acef2858185fe09a0917c741169

Contents?: true

Size: 696 Bytes

Versions: 4

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Logic
    module Operations
      class Set < Abstract
        def type
          :set
        end

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

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

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

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-1.6.0 lib/dry/logic/operations/set.rb
dry-logic-1.5.0 lib/dry/logic/operations/set.rb
dry-logic-1.4.0 lib/dry/logic/operations/set.rb
dry-logic-1.3.0 lib/dry/logic/operations/set.rb