Sha256: 191ced25068eb6d2bc6d5e5ff85a66f87be5ea27dfc3893b3aae50674905a53b

Contents?: true

Size: 1.11 KB

Versions: 32

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Dry
  module Schema
    module Extensions
      module Hints
        # Hint extensions for MessageSet
        #
        # @api public
        module MessageSetMethods
          # Filtered message hints from all messages
          #
          # @return [Array<Message::Hint>]
          attr_reader :hints

          # Configuration option to enable/disable showing errors
          #
          # @return [Boolean]
          attr_reader :failures

          # @api private
          def initialize(messages, options = EMPTY_HASH)
            super
            @hints = messages.select(&:hint?)
            @failures = options.fetch(:failures, true)
          end

          # Dump message set to a hash with either all messages or just hints
          #
          # @see MessageSet#to_h
          # @see ResultMethods#hints
          #
          # @return [Hash<Symbol=>Array<String>>]
          #
          # @api public
          def to_h
            @to_h ||= failures ? messages_map : messages_map(hints)
          end
          alias_method :to_hash, :to_h
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
dry-schema-1.13.3 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.13.2 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.13.1 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.13.0 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.12.0 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.11.3 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.11.2 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.11.1 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.11.0 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.10.6 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.10.5 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.10.4 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.10.3 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.10.2 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.10.1 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.9.3 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.9.2 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.9.1 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.9.0 lib/dry/schema/extensions/hints/message_set_methods.rb
dry-schema-1.8.0 lib/dry/schema/extensions/hints/message_set_methods.rb