dry-schema 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/LICENSE +1 -1
- data/README.md +0 -2
- data/lib/dry/schema.rb +1 -1
- data/lib/dry/schema/dsl.rb +2 -4
- data/lib/dry/schema/extensions/hints/message_compiler_methods.rb +1 -1
- data/lib/dry/schema/key.rb +4 -4
- data/lib/dry/schema/macros/core.rb +2 -2
- data/lib/dry/schema/macros/dsl.rb +10 -4
- data/lib/dry/schema/macros/key.rb +2 -1
- data/lib/dry/schema/message_compiler.rb +4 -4
- data/lib/dry/schema/messages/abstract.rb +1 -7
- data/lib/dry/schema/messages/i18n.rb +25 -1
- data/lib/dry/schema/messages/template.rb +1 -1
- data/lib/dry/schema/processor.rb +1 -1
- data/lib/dry/schema/result.rb +1 -1
- data/lib/dry/schema/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ebd83b8cd1025c9f732f593b47d52583455bac56def9866901a374cd9f24dc11
         | 
| 4 | 
            +
              data.tar.gz: def7d4f585ab856a055667474bc6cb59e7f012e13dcf0a4a9d17daa9b0ea53d1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 77a2481151c16aa91e1a29a32e640adadfcefcbceacbd5e1e8cdfcd63c29d186dbc17640d9da0974c37a2e152440da723fd516cac7362cd195b24630011905d0
         | 
| 7 | 
            +
              data.tar.gz: c5cf256d2b61a3dc7b832f68d6ce64c735f00a7885f42a05f53f67a07ec6108322d996ea243387dc91b5acfbb57765129e8d25bfecbb2c151a5e18ac3c709c50
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,14 @@ | |
| 1 | 
            +
            # 1.4.2 2019-12-19
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ### Fixed
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            * `I18n` messages backend supports procs as text properly (issue #208) (@robhanlon22)
         | 
| 6 | 
            +
            * `I18n` messages backend supports message meta-data (issue #210) (@robhanlon22)
         | 
| 7 | 
            +
            * Fixed keyword warnings from MRI 2.7.0 (@flash-gordon)
         | 
| 8 | 
            +
            * Array with a member works correctly with `maybe` (issue #206) (@solnic)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            [Compare v1.4.1...v1.4.2](https://github.com/dry-rb/dry-schema/compare/v1.4.1...v1.4.2)
         | 
| 11 | 
            +
             | 
| 1 12 | 
             
            # 1.4.1 2019-10-08
         | 
| 2 13 |  | 
| 3 14 | 
             
            ### Fixed
         | 
    
        data/LICENSE
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,4 @@ | |
| 1 1 | 
             
            [gem]: https://rubygems.org/gems/dry-schema
         | 
| 2 | 
            -
            [travis]: https://travis-ci.com/dry-rb/dry-schema
         | 
| 3 2 | 
             
            [actions]: https://github.com/dry-rb/dry-schema/actions
         | 
| 4 3 | 
             
            [codeclimate]: https://codeclimate.com/github/dry-rb/dry-schema
         | 
| 5 4 | 
             
            [chat]: https://dry-rb.zulipchat.com
         | 
| @@ -8,7 +7,6 @@ | |
| 8 7 | 
             
            # dry-schema [][chat]
         | 
| 9 8 |  | 
| 10 9 | 
             
            [][gem]
         | 
| 11 | 
            -
            [][travis]
         | 
| 12 10 | 
             
            [][actions]
         | 
| 13 11 | 
             
            [][codeclimate]
         | 
| 14 12 | 
             
            [][codeclimate]
         | 
    
        data/lib/dry/schema.rb
    CHANGED
    
    
    
        data/lib/dry/schema/dsl.rb
    CHANGED
    
    | @@ -51,8 +51,6 @@ module Dry | |
| 51 51 |  | 
| 52 52 | 
             
                  extend Dry::Initializer
         | 
| 53 53 |  | 
| 54 | 
            -
                  include ::Dry::Equalizer(:options)
         | 
| 55 | 
            -
             | 
| 56 54 | 
             
                  # @return [Compiler] The rule compiler object
         | 
| 57 55 | 
             
                  option :compiler, default: -> { Compiler.new }
         | 
| 58 56 |  | 
| @@ -275,8 +273,8 @@ module Dry | |
| 275 273 | 
             
                  # @return [Dry::Types::Safe]
         | 
| 276 274 | 
             
                  #
         | 
| 277 275 | 
             
                  # @api private
         | 
| 278 | 
            -
                  def new(options | 
| 279 | 
            -
                    self.class.new(options | 
| 276 | 
            +
                  def new(**options, &block)
         | 
| 277 | 
            +
                    self.class.new(**options, processor_type: processor_type, config: config, &block)
         | 
| 280 278 | 
             
                  end
         | 
| 281 279 |  | 
| 282 280 | 
             
                  # Set a type for the given key name
         | 
    
        data/lib/dry/schema/key.rb
    CHANGED
    
    | @@ -27,8 +27,8 @@ module Dry | |
| 27 27 | 
             
                  end
         | 
| 28 28 |  | 
| 29 29 | 
             
                  # @api private
         | 
| 30 | 
            -
                  def self.new(*args)
         | 
| 31 | 
            -
                    fetch_or_store( | 
| 30 | 
            +
                  def self.new(*args, **kwargs)
         | 
| 31 | 
            +
                    fetch_or_store(args, kwargs) { super }
         | 
| 32 32 | 
             
                  end
         | 
| 33 33 |  | 
| 34 34 | 
             
                  # @api private
         | 
| @@ -65,8 +65,8 @@ module Dry | |
| 65 65 | 
             
                  end
         | 
| 66 66 |  | 
| 67 67 | 
             
                  # @api private
         | 
| 68 | 
            -
                  def new(new_opts | 
| 69 | 
            -
                    self.class.new(id,  | 
| 68 | 
            +
                  def new(**new_opts)
         | 
| 69 | 
            +
                    self.class.new(id, name: name, coercer: coercer, **new_opts)
         | 
| 70 70 | 
             
                  end
         | 
| 71 71 |  | 
| 72 72 | 
             
                  # @api private
         | 
| @@ -28,8 +28,8 @@ module Dry | |
| 28 28 | 
             
                    option :schema_dsl, optional: true
         | 
| 29 29 |  | 
| 30 30 | 
             
                    # @api private
         | 
| 31 | 
            -
                    def new(options | 
| 32 | 
            -
                      self.class.new( | 
| 31 | 
            +
                    def new(**options)
         | 
| 32 | 
            +
                      self.class.new(name: name, compiler: compiler, schema_dsl: schema_dsl, **options)
         | 
| 33 33 | 
             
                    end
         | 
| 34 34 |  | 
| 35 35 | 
             
                    # @api private
         | 
| @@ -57,11 +57,12 @@ module Dry | |
| 57 57 | 
             
                    # @return [Macros::Core]
         | 
| 58 58 | 
             
                    #
         | 
| 59 59 | 
             
                    # @api public
         | 
| 60 | 
            -
                    def value(*predicates,  | 
| 60 | 
            +
                    def value(*predicates, &block)
         | 
| 61 61 | 
             
                      append_macro(Macros::Value) do |macro|
         | 
| 62 | 
            -
                        macro.call(*predicates,  | 
| 62 | 
            +
                        macro.call(*predicates, &block)
         | 
| 63 63 | 
             
                      end
         | 
| 64 64 | 
             
                    end
         | 
| 65 | 
            +
                    ruby2_keywords :value if respond_to?(:ruby2_keywords, true)
         | 
| 65 66 |  | 
| 66 67 | 
             
                    # Prepends `:filled?` predicate
         | 
| 67 68 | 
             
                    #
         | 
| @@ -74,11 +75,12 @@ module Dry | |
| 74 75 | 
             
                    # @return [Macros::Core]
         | 
| 75 76 | 
             
                    #
         | 
| 76 77 | 
             
                    # @api public
         | 
| 77 | 
            -
                    def filled(*args,  | 
| 78 | 
            +
                    def filled(*args, &block)
         | 
| 78 79 | 
             
                      append_macro(Macros::Filled) do |macro|
         | 
| 79 | 
            -
                        macro.call(*args,  | 
| 80 | 
            +
                        macro.call(*args, &block)
         | 
| 80 81 | 
             
                      end
         | 
| 81 82 | 
             
                    end
         | 
| 83 | 
            +
                    ruby2_keywords :filled if respond_to?(:ruby2_keywords, true)
         | 
| 82 84 |  | 
| 83 85 | 
             
                    # Specify a nested hash without enforced `hash?` type-check
         | 
| 84 86 | 
             
                    #
         | 
| @@ -99,6 +101,7 @@ module Dry | |
| 99 101 | 
             
                        macro.call(*args, &block)
         | 
| 100 102 | 
             
                      end
         | 
| 101 103 | 
             
                    end
         | 
| 104 | 
            +
                    ruby2_keywords :schema if respond_to?(:ruby2_keywords, true)
         | 
| 102 105 |  | 
| 103 106 | 
             
                    # Specify a nested hash with enforced `hash?` type-check
         | 
| 104 107 | 
             
                    #
         | 
| @@ -113,6 +116,7 @@ module Dry | |
| 113 116 | 
             
                        macro.call(*args, &block)
         | 
| 114 117 | 
             
                      end
         | 
| 115 118 | 
             
                    end
         | 
| 119 | 
            +
                    ruby2_keywords :hash if respond_to?(:ruby2_keywords, true)
         | 
| 116 120 |  | 
| 117 121 | 
             
                    # Specify predicates that should be applied to each element of an array
         | 
| 118 122 | 
             
                    #
         | 
| @@ -136,6 +140,7 @@ module Dry | |
| 136 140 | 
             
                        macro.value(*args, &block)
         | 
| 137 141 | 
             
                      end
         | 
| 138 142 | 
             
                    end
         | 
| 143 | 
            +
                    ruby2_keywords :each if respond_to?(:ruby2_keywords, true)
         | 
| 139 144 |  | 
| 140 145 | 
             
                    # Like `each` but sets `array?` type-check
         | 
| 141 146 | 
             
                    #
         | 
| @@ -155,6 +160,7 @@ module Dry | |
| 155 160 | 
             
                        macro.value(*args, &block)
         | 
| 156 161 | 
             
                      end
         | 
| 157 162 | 
             
                    end
         | 
| 163 | 
            +
                    ruby2_keywords :array if respond_to?(:ruby2_keywords, true)
         | 
| 158 164 |  | 
| 159 165 | 
             
                    # Set type spec
         | 
| 160 166 | 
             
                    #
         | 
| @@ -30,6 +30,7 @@ module Dry | |
| 30 30 | 
             
                      (filter_schema_dsl[name] || filter_schema_dsl.optional(name)).value(*args, &block)
         | 
| 31 31 | 
             
                      self
         | 
| 32 32 | 
             
                    end
         | 
| 33 | 
            +
                    ruby2_keywords(:filter) if respond_to?(:ruby2_keywords, true)
         | 
| 33 34 |  | 
| 34 35 | 
             
                    # @overload value(type_spec, *predicates, **predicate_opts)
         | 
| 35 36 | 
             
                    #   Set type specification and predicates
         | 
| @@ -87,7 +88,7 @@ module Dry | |
| 87 88 | 
             
                    def maybe(*args, **opts, &block)
         | 
| 88 89 | 
             
                      extract_type_spec(*args, nullable: true) do |*predicates, type_spec:|
         | 
| 89 90 | 
             
                        append_macro(Macros::Maybe) do |macro|
         | 
| 90 | 
            -
                          macro.call(*predicates, **opts, &block)
         | 
| 91 | 
            +
                          macro.call(*predicates, type_spec: type_spec, **opts, &block)
         | 
| 91 92 | 
             
                        end
         | 
| 92 93 | 
             
                      end
         | 
| 93 94 | 
             
                    end
         | 
| @@ -41,7 +41,7 @@ module Dry | |
| 41 41 | 
             
                  attr_reader :default_lookup_options
         | 
| 42 42 |  | 
| 43 43 | 
             
                  # @api private
         | 
| 44 | 
            -
                  def initialize(messages, options | 
| 44 | 
            +
                  def initialize(messages, **options)
         | 
| 45 45 | 
             
                    super
         | 
| 46 46 | 
             
                    @options = options
         | 
| 47 47 | 
             
                    @default_lookup_options = options[:locale] ? { locale: locale } : EMPTY_HASH
         | 
| @@ -55,7 +55,7 @@ module Dry | |
| 55 55 |  | 
| 56 56 | 
             
                    return self if updated_opts.eql?(options)
         | 
| 57 57 |  | 
| 58 | 
            -
                    self.class.new(messages, updated_opts)
         | 
| 58 | 
            +
                    self.class.new(messages, **updated_opts)
         | 
| 59 59 | 
             
                  end
         | 
| 60 60 |  | 
| 61 61 | 
             
                  # @api private
         | 
| @@ -105,7 +105,7 @@ module Dry | |
| 105 105 | 
             
                    left, right = node.map { |n| visit(n, opts) }
         | 
| 106 106 |  | 
| 107 107 | 
             
                    if [left, right].flatten.map(&:path).uniq.size == 1
         | 
| 108 | 
            -
                      Message::Or.new(left, right, proc { |k| messages.translate(k, default_lookup_options) })
         | 
| 108 | 
            +
                      Message::Or.new(left, right, proc { |k| messages.translate(k, **default_lookup_options) })
         | 
| 109 109 | 
             
                    elsif right.is_a?(Array)
         | 
| 110 110 | 
             
                      right
         | 
| 111 111 | 
             
                    else
         | 
| @@ -116,7 +116,7 @@ module Dry | |
| 116 116 | 
             
                  # @api private
         | 
| 117 117 | 
             
                  def visit_namespace(node, opts)
         | 
| 118 118 | 
             
                    ns, rest = node
         | 
| 119 | 
            -
                    self.class.new(messages.namespaced(ns), options).visit(rest, opts)
         | 
| 119 | 
            +
                    self.class.new(messages.namespaced(ns), **options).visit(rest, opts)
         | 
| 120 120 | 
             
                  end
         | 
| 121 121 |  | 
| 122 122 | 
             
                  # @api private
         | 
| @@ -123,13 +123,7 @@ module Dry | |
| 123 123 |  | 
| 124 124 | 
             
                      return unless path
         | 
| 125 125 |  | 
| 126 | 
            -
                       | 
| 127 | 
            -
             | 
| 128 | 
            -
                      if text.is_a?(Hash)
         | 
| 129 | 
            -
                        text.values_at(:text, :meta)
         | 
| 130 | 
            -
                      else
         | 
| 131 | 
            -
                        [text, EMPTY_HASH]
         | 
| 132 | 
            -
                      end
         | 
| 126 | 
            +
                      get(path, opts).values_at(:text, :meta)
         | 
| 133 127 | 
             
                    end
         | 
| 134 128 | 
             
                    # rubocop:enable Metrics/AbcSize
         | 
| 135 129 |  | 
| @@ -29,7 +29,24 @@ module Dry | |
| 29 29 | 
             
                  #
         | 
| 30 30 | 
             
                  # @api public
         | 
| 31 31 | 
             
                  def get(key, options = EMPTY_HASH)
         | 
| 32 | 
            -
                     | 
| 32 | 
            +
                    return unless key
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    opts = { locale: options.fetch(:locale, default_locale) }
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    translation = t.(key, opts)
         | 
| 37 | 
            +
                    text_key = "#{key}.text"
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    if !translation.is_a?(Hash) || !key?(text_key, opts)
         | 
| 40 | 
            +
                      return {
         | 
| 41 | 
            +
                        text: translation,
         | 
| 42 | 
            +
                        meta: EMPTY_HASH
         | 
| 43 | 
            +
                      }
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    {
         | 
| 47 | 
            +
                      text: t.(text_key, opts),
         | 
| 48 | 
            +
                      meta: extract_meta(key, translation, opts)
         | 
| 49 | 
            +
                    }
         | 
| 33 50 | 
             
                  end
         | 
| 34 51 |  | 
| 35 52 | 
             
                  # Check if given key is defined
         | 
| @@ -100,6 +117,13 @@ module Dry | |
| 100 117 | 
             
                      I18n.backend.store_translations(locale, data[locale.to_s])
         | 
| 101 118 | 
             
                    end
         | 
| 102 119 | 
             
                  end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                  def extract_meta(parent_key, translation, options)
         | 
| 122 | 
            +
                    translation.keys.each_with_object({}) do |k, meta|
         | 
| 123 | 
            +
                      meta_key = "#{parent_key}.#{k}"
         | 
| 124 | 
            +
                      meta[k] = t.(meta_key, options) if k != :text && key?(meta_key, options)
         | 
| 125 | 
            +
                    end
         | 
| 126 | 
            +
                  end
         | 
| 103 127 | 
             
                end
         | 
| 104 128 | 
             
              end
         | 
| 105 129 | 
             
            end
         | 
    
        data/lib/dry/schema/processor.rb
    CHANGED
    
    
    
        data/lib/dry/schema/result.rb
    CHANGED
    
    
    
        data/lib/dry/schema/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dry-schema
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.4. | 
| 4 | 
            +
              version: 1.4.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Piotr Solnica
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-12-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: concurrent-ruby
         |