Skip to content

Releases: dry-rb/dry-types

v1.7.2

05 Jan 06:28
v1.7.2
Compare
Choose a tag to compare

Fixed

  • Fixed BigDecimal warning due to not being required in gemspec (@bkuhlmann in #464)

Compare v1.7.1...v1.7.2

v1.7.1

17 Feb 07:58
v1.7.1
Compare
Choose a tag to compare

Fixed

Compare v1.7.0...v1.7.1

v1.7.0

04 Nov 17:02
v1.7.0
Compare
Choose a tag to compare

Changed

Compare v1.6.1...v1.7.0

v1.6.1

15 Oct 07:53
v1.6.1
Compare
Choose a tag to compare

Changed

Compare v1.6.0...v1.6.1

v1.6.0

15 Oct 05:35
v1.6.0
Compare
Choose a tag to compare

Changed

Compare v1.5.1...v1.6.0

v1.5.1

16 Feb 11:26
Compare
Choose a tag to compare

Fixed

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

Compare v1.5.0...v1.5.1

v1.5.0

21 Jan 18:45
v1.5.0
Compare
Choose a tag to compare

Added

  • Wrapping constructor types 🎉 (@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 🎉 (@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

09 Mar 13:25
v1.4.0
Compare
Choose a tag to compare

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

16 Feb 20:37
v1.3.1
Compare
Choose a tag to compare

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

10 Feb 14:46
v1.3.0
bd86307
Compare
Choose a tag to compare

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
  • 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