Skip to content

Releases: AaronLasseigne/active_interaction

v5.3.0

06 May 21:37
Compare
Choose a tag to compare

Added

  • Added predicate methods for boolean values. Thanks @heka1024

Fixed

  • #554 - Non-detailed error should not lose options when merged.
  • #553 - Improve error handling and documentation for hash filter defaults.

v5.2.0

22 Oct 03:00
Compare
Choose a tag to compare

Added

Fixed

v5.1.1

01 Sep 00:53
Compare
Choose a tag to compare

Fixed

  • #539 - Fixed a caching error in default values.

v5.1.0

28 Jul 02:23
Compare
Choose a tag to compare

Added

  • Limit dependencies to the minimum requirements.

Fixed

  • #536 - compose accepts Inputs.
  • #537 - Arrays with nested filters returned the wrong value.

v5.0.0

24 Jun 02:02
Compare
Choose a tag to compare

Changed

  • Drop support for JRuby.
  • Drop support for Ruby 2.5 and 2.6, adding support for 3.1
  • Drop support for Rails 5.0 and 5.1
  • ActiveInteraction::Inputs no longer inherits from Hash though it still has most of the methods
    provided by Hash (methods that write were removed).
  • Removed Filter#clean (use Filter#process and call #value on the result)
  • The given? method has been moved onto inputs. (see Upgrade section below)
  • #503 - The record filter now treats blank strings value as nil. This was missed in the 4.0 update.
  • The type_check callback has been renamed to filter to better match the reality of what it does.
    (see Upgrade section below)
  • ActiveIneraction::FilterColumn is now ActiveInteraction::Filter::Column
  • Errors on the array filter will now be indexed if the Rails config index_nested_attribute_errors
    is true or the :index_errors option is set to true. The :index_errors option always overrides
    the Rails config.
  • Invalid nested errors (:invalid_nested) are gone. Instead the nested errors will appear as they would
    in Rails if they were a has_many relationship being assigned attributes through a parent.
    (see Upgrade section below)

Added

  • Filter#process which returns an Input.

Fixed

  • When passing an ActiveRecord::Relation in an array filter with no inner
    filter, the value returned was an ActiveRecord::Relation instead of an
    Array.

Upgrading

given?

The given? method can now be found on inputs. It works the same as before.

# 4.1
class Example < ActiveInteraction::Base
  string :name, default: nil

  def execute
    given?(:name)
  end
end

# 5.0
class Example < ActiveInteraction::Base
  string :name, default: nil

  def execute
    inputs.given?(:name)
  end
end

Filter Callback

You'll need to rename any :type_check callbacks to :filter.

# 4.1
set_callback :type_check, :before, -> { puts 'before type check' }

# 5.0
set_callback :filter, :before, -> { puts 'before type check' }

Nested Hash Errors

Nested hash errors no longer add an error as through it happened on the hash.
They now use the error in its original form and attach the name of the hash to
the error. It is also not limited to returning one error.

class HashInteraction < ActiveInteraction::Base
  hash :mailing_lists do
    boolean :marketing
    boolean :product_updates
  end

  def execute
    # ...
  end
end

> outcome = HashInteraction.run(mailing_lists: {})

# 4.1
> outcome.errors.details
# => {:mailing_lists=>[{:error=>:invalid_nested, :name=>"\"marketing\"", :value=>"nil"}]},
> outcome.errors.messages
# => {:mailing_lists=>["has an invalid nested value (\"marketing\" => nil)"]}
> outcome.errors.full_messages
# => ["Mailing lists has an invalid nested value (\"marketing\" => nil)"]

# 5.0
> outcome.errors.details
# => {:"mailing_lists.marketing"=>[{:error=>:missing}], :"mailing_lists.product_updates"=>[{:error=>:missing}]}
> outcome.errors.messages
# => {:"mailing_lists.marketing"=>["is required"], :"mailing_lists.product_updates"=>["is required"]}
> outcome.errors.full_messages
# => ["Mailing lists marketing is required", "Mailing lists product updates is required"]

I18n can handle these values the same as nested values in Rails:

en:
  active_interaction:
    attributes:
      hash_interaction/mailing_lists:
        marketing: 'Mailing list "Marketing"'
        product_updates: 'Mailing list "Product Updates"'

Using the same example from above:

> outcome.errors.full_messages
# => ["Mailing list \"Marketing\" is required", "Mailing list \"Product Updates\" is required"]

v4.1.0

30 Dec 02:12
Compare
Choose a tag to compare

Added

  • #518 - Add Rails 7 support

v4.0.6

14 Oct 00:23
Compare
Choose a tag to compare

Fixed

  • #515 - Filters nested in arrays should accept default values as indicated in the documentation.

v4.0.5

11 Jul 18:26
Compare
Choose a tag to compare

Fixed

  • #480 - Interfaces used inside hashes failed to recognize nil as a non-value.

v4.0.4

03 Jul 21:01
Compare
Choose a tag to compare

Fixed

  • #510 - Hash parameters failed when working outside of Rails.
  • #511 - Nested filters with options but no :class failed to have :class automatically added.

v4.0.3

25 Jun 04:07
Compare
Choose a tag to compare

Fixed

  • #499 - given? now recognizes multi-part date inputs by their primary key name
  • #493 - compose now properly accepts Inputs