:briefcase: Manage application specific business logic.
ActiveInteraction::Inputs
no longer inherits from Hash
though it still has most of the methods
provided by Hash
(methods that write were removed).Filter#clean
(use Filter#process
and call #value
on the result)given?
method has been moved onto inputs
. (see Upgrade section below)nil
. This was missed in the 4.0 update.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
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
) 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)Filter#process
which returns an Input
.ActiveRecord::Relation
in an array filter with no inner
filter, the value returned was an ActiveRecord::Relation
instead of an
Array.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
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 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"]