Sha256: a2311dc00b4c4dcab303379e6b10cf0bd28af27679823c50f43c4edeca847bf4

Contents?: true

Size: 747 Bytes

Versions: 16

Compression:

Stored size: 747 Bytes

Contents

# frozen_string_literal: true

require "dry/schema/message/or/single_path"
require "dry/schema/message/or/multi_path"

module Dry
  module Schema
    # Message objects used by message sets
    #
    # @api public
    class Message
      module Or
        # @api private
        def self.[](left, right, messages)
          msgs = [left, right].flatten
          paths = msgs.map(&:path)

          if paths.uniq.size == 1
            SinglePath.new(left, right, messages)
          elsif right.is_a?(Array)
            if left.is_a?(Array) && paths.uniq.size > 1
              MultiPath.new(left, right)
            else
              right
            end
          else
            msgs.max
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dry-schema-1.9.2 lib/dry/schema/message/or.rb
dry-schema-1.9.1 lib/dry/schema/message/or.rb
dry-schema-1.9.0 lib/dry/schema/message/or.rb
dry-schema-1.8.0 lib/dry/schema/message/or.rb
dry-schema-1.7.1 lib/dry/schema/message/or.rb
dry-schema-1.7.0 lib/dry/schema/message/or.rb
dry-schema-1.6.2 lib/dry/schema/message/or.rb
dry-schema-1.6.1 lib/dry/schema/message/or.rb
dry-schema-1.6.0 lib/dry/schema/message/or.rb
dry-schema-1.5.6 lib/dry/schema/message/or.rb
dry-schema-1.5.5 lib/dry/schema/message/or.rb
dry-schema-1.5.4 lib/dry/schema/message/or.rb
dry-schema-1.5.3 lib/dry/schema/message/or.rb
dry-schema-1.5.2 lib/dry/schema/message/or.rb
dry-schema-1.5.1 lib/dry/schema/message/or.rb
dry-schema-1.5.0 lib/dry/schema/message/or.rb