Sha256: b7baa518a8b2c2194619e6fde711d22886964b33a82120bd839d94402372cccb

Contents?: true

Size: 694 Bytes

Versions: 1

Compression:

Stored size: 694 Bytes

Contents

module Dry
  module Logic
    class Rule::Result < Rule
      def call(input)
        result = if name.is_a?(Hash)
                   parent, _ = name.to_a.flatten
                   input[parent]
                 else
                   input[name]
                 end

        if result.success?
          Result::Wrapped.new(input, predicate.(evaluate_input(input)), self)
        else
          result
        end
      end

      def evaluate_input(result)
        if name.is_a?(Hash)
          parent, child = name.to_a.flatten
          result[parent].input[child]
        else
          result[name].input
        end
      end

      def type
        :res
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-logic-0.1.4 lib/dry/logic/rule/result.rb