All Versions
52
Latest Version
Avg Release Cycle
65 days
Latest Release
292 days ago

Changelog History
Page 1

  • v1.5.1 Changes

    February 16, 2021

    ๐Ÿ›  Fixed

    • โž• Add missing requires for internal usage of Dry::Equalizer (@timriley in #418)

    Compare v1.5.0...v1.5.1

  • v1.5.0 Changes

    January 21, 2021

    โž• Added

    • Wrapping constructor types :tada: (@flash-gordon)

    Constructor blocks can have a second argument. The second argument is the underlying type itself:

      age_from_year = Dry::Types['coercible.integer'].constructor do |input, type|
        Date.today.year - type.(input)
      end
      age_from_year.('2000') # => 21
    

    With wrapping constructors you have control over "type application". You can even run it more than once:

      inc = Dry::Types['integer'].constructor(&:succ)
      inc2x = inc.constructor { _2.(_2.(_2.(_1))) }
      inc2x.(10) # => 13
    
    • Fallbacks :tada: (@flash-gordon)
      age = Dry::Types['coercible.ineger'].fallback(18)
      age.('10') # => 10
      age.('20') # => 20
      age.('abc') # => 18
    

    Fallbacks are different from default values: the later will be evaluated only when no input provided.

    Under the hood, .fallback creates a wrapping constructor.

    • params.string as an alias for strict.string. This addition should be non-breaking (@flash-gordon)
    • ๐Ÿ— API for defining custom type builders similar to .default, .constructor, or .optional (@flash-gordon)
      # Making an alias for `.fallback`
      Dry::Types.define_builder(:or) { |type, v| type.fallback(v) }
    
      # Using new builder
      type = Dry::Types['integer'].or(-273)
      type.(:invalid) # => -273
    

    ๐Ÿ”„ Changed

    • ๐Ÿ—„ Inferring predicates from class names is deprecated. It's very unlikely your code depends on it, however, if it does, you'll get an exception with instructions. (@flash-gordon)

    If you don't rely on inferring, just disable it with:

      Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name false
    

    Otherwise, enable it explicitly:

      Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name true
    

    Compare v1.4.0...v1.5.0

  • v1.4.0 Changes

    March 09, 2020

    1.4.0 2020-03-09

    ๐Ÿ›  Fixed

    • json.nil no longer coerces empty strings to nil. It was a long-standing
      ๐Ÿ› bug that for some reason remained unnoticed for years. Technically,
      this may be a breaking change for JSON schemas described with dry-schema (@flash-gordon)

    Compare v1.3.1...v1.4.0

  • v1.3.1 Changes

    February 17, 2020

    1.3.1 2020-02-17

    ๐Ÿ”„ Changed

    • Predicate inferrer now returns hash? for hash schemas. Note, it doesn't spit more complex preds because we have different plans for dry-schema (@flash-gordon)

    Compare v1.3.0...v1.3.1

  • v1.3.0 Changes

    February 10, 2020

    โž• Added

    • ๐Ÿ”€ Schema#merge for merging two hash schemas (@waiting-for-dev)
    • Aliases for .constructor to non-constructor types. Now you can call .prepend/.append without silly checks for the type being a constructor (flash-gordon)

      (Dry::Types['integer'].prepend(-> { _1 + 1 })).(1) # => 2(Dry::Types['coercible.integer'] >> -> { _1 * 2 }).('99') # => 198

    • Hash::Schema#clear returns a schema with the same options but without keys

    • 0๏ธโƒฃ Optional namespace now includes strict types by default (@flash-gordon)

    ๐Ÿ›  Fixed

    • Schema::Key#optional returns an instance of Schema::Key as it should have done
    • Composition with function handling exceptions. This could occasionally lead to unexpected exceptions (@flash-gordon)

    Compare v1.2.2...v1.3.0

  • v1.2.2 Changes

    December 14, 2019

    1.2.2 2019-12-14

    ๐Ÿ›  Fixed

    • ๐Ÿ›  Types.Contructor doesn't re-wrap class instances implementing type interface, this fixes some quirks in dry-struct (flash-gordon)

    ๐Ÿ”„ Changed

    • ๐ŸŽ Types now use immutable equalizers. This should improve performance in certain cases e.g. in ROM (flash-gordon)
    • Attempting to use non-symbol keys in hash schemas raises an error. We always supported only symbols as keys, but there was no check, now it'll throw an argument error. If you want to convert strings to symbols, use Hash#with_key_transform (flash-gordon)
    • ๐Ÿ— Params and JSON types accept Time/Date/Datetime instances and boolean values. This can be useful in tests, but we discourage you from relying on this behavior in production code. For example, building structs with Params types is considered a smell. There are dedicated tools for coercion, namely dry-schema and dry-validation. Be a responsible user of dry-types! โค (flash-gordon)

    Compare v1.2.1...v1.2.2

  • v1.2.1 Changes

    November 07, 2019

    1.2.1 2019-11-07

    ๐Ÿ›  Fixed

    • ๐Ÿ›  Fix keyword warnings reported by Ruby 2.7 (flash-gordon)
    • Error type in failing case in Array::Member (esparta)

    Compare v1.2.0...v1.2.1

  • v1.2.0 Changes

    October 06, 2019

    โž• Added

    • Optional::Params types that coerce empty strings to nil (flash-gordon) ruby Dry::Types['optional.params.integer'].('') # => nil Dry::Types['optional.params.integer'].('140') # => 140 Dry::Types['optional.params.integer'].('asd') # => exception! Keep in mind, Dry::Types['optional.params.integer'] and Dry::Types['params.integer'].optional are not the same, the latter doesn't handle empty strings.
    • Predicate inferrer was ported from dry-schema (authored by solnic) ruby require 'dry/types/predicate_inferrer' Dry::Types::PredicateInferrer.new[Types::String] # => [:str?] Dry::Types::PredicateInferrer.new[Types::String | Types::Integer] # => [[[:str?], [:int?]]] Note that the API of the predicate inferrer can change in the stable version, it's dictated by the needs of dry-schema so it should be considered as semi-stable. If you depend on it, write specs covering the desired behavior. Another option is copy-and-paste the whole thing to your project.
    • Primitive inferrer was ported from dry-schema (authored by solnic) ruby require 'dry/types/primitive_inferrer' Dry::Types::PrimitiveInferrer.new[Types::String] # => [String] Dry::Types::PrimitiveInferrer.new[Types::String | Types::Integer] # => [String, Integer] Dry::Types::PrimitiveInferrer.new[Types::String.optional] # => [NilClass, String] The primitive inferrer should be stable by now, you can rely on it.
    • The monads extension adds Dry::Types::Result#to_monad. This makes it compatible with do notation from dry-monads. Load it with Dry::Types.load_extensions(:monads) (skryukov)
      Types = Dry.Types
      Dry::Types.load_extensions(:monads)
    
      class AddTen
        include Dry::Monads[:result, :do]
    
        def call(input)
          integer = yield Types::Coercible::Integer.try(input)
    
          Success(integer + 10)
        end
      end
    

    ๐Ÿ›  Fixed

    • ๐Ÿ› Bug with using a Bool-named struct as a schema key (flash-gordon)
    • A bunch of issues related to using meta on complex types (flash-gordon)
    • Types.Constructor(...) returns a Types::Array as it should (flash-gordon)

    ๐Ÿ”„ Changed

    • ๐Ÿ—„ Dry::Types.[] used to work with classes, now it's deprecated (flash-gordon)

    Compare v1.1.1...v1.2.0

  • v1.1.1 Changes

    July 26, 2019

    1.1.1 2019-07-26

    ๐Ÿ›  Fixed

    • A bug where meta was lost for lax array types (flash-gordon)

    Compare v1.1.0...v1.1.1

  • v1.1.0 Changes

    July 02, 2019

    โž• Added

    • ๐Ÿ†• New builder method Interface constructs a type which accepts objects that respond to the given methods (waiting-for-dev) ruby Types = Dry.Types() Types::Callable = Types.Interface(:call) Types::Callable.valid?(Object.new) # => false Types::Callable.valid?(proc {}) # => true
    • ๐Ÿ†• New types: coercible.symbol, params.symbol, and json.symbol, all use .to_sym for coercion (waiting-for-dev)

    ๐Ÿ›  Fixed

    • Converting schema keys to maybe types (flash-gordon)
    • Using Schema#key and Array#member on constuctors (flash-gordon)
    • โš  Using meta(omittable: true) within transform_types works again but produces a warning, please migrate to .omittable or .required(false) (flash-gordon)
    • ๐Ÿ› Bug with a constructror defined on top of enum (flash-gordon)

    Compare v1.0.1...v1.1.0