Releases: taylorthurlow/interaktor
v0.6.0.pre2
Please see the notes for 0.6.0.pre for details pertaining to the prerelease in general.
Breaking changes
- Support for the the normalization feature provided by
ActiveModel::Attributes::Normalizationhas been removed. The normalization module also includesActiveModel::Dirty, which provides methods like<attr>_changed?,changes, and<attr>_changes, which interfere/override attribute methods that could otherwise be defined in an interaktor.
v0.6.0.pre
This is a pre-release of v0.6.0. I'm not expecting any further changes, but I'm trying to test things out in a production environment before committing to the full release.
This release is a significant change from prior versions - attribute definition is no longer done with the Dry::Schema builder. Instead, they are now done with the ActiveModel attribute DSL, which is the same DSL used internally by ActiveRecord. Validations also come along with this change, which are the same validations you would find on an ActiveRecord model.
The primary motivation for this change is not that I dislike Dry::Schema (over the years using this gem it is not my favorite, but it works well for this use case), but that it became clear that more complex attribute schemas just did not function correctly. This gem relied on a built-in "extension" (called info) which allows introspection into a schema to determine which schema attributes are required and which are optional - this extension just does not function (raises an exception) for certain complex schemas (like ones that use logical OR or XOR).
Pre-1.0 is the time to make this sort of change so I decided to cut losses and switch to ActiveModel, which is a little more tried and true, and suits this use case a little better. Along with this comes some cooler features like value normalization (with activemodel >= 8.1), primitive attribute type definitions and value coercion, and the entire suite of validation predicates most Ruby developers have used before in ActiveRecord.
Breaking changes
- Attribute definitions now use
activemodel. See the README for examples. The minimum version ofactivemodelallowed is7.0.9- earlier versions do not initialize correctly - I don't think versions earlier than this were intended to be used outside of an ActiveRecord model context, so it's not entirely surprising they don't work. - Some attribute names are now completely disallowed, and defining them will raise an exception. Currently the list of disallowed attribute names is just the list of instance method names that already exist on
Interaktor::Attributes, the superclass used internally by Interaktor to manage attributes and their values. This list is defined atInteraktor::Attributes::DISALLOWED_ATTRIBUTE_NAMES. Examples of now-disallowed attribute names that may have been used commonly areerrors,attributes,attribute_names,class,method,methods,changes,changed,model_name,hash,object_id, andsend. - An exception will be raised if an
input,success, orfailureblock is defined more than once on an interaktor.
v0.5.1
v0.5.0
Minor breaking changes in this release.
Calling an interaktor now returns an Interaktor::Interaction instance, instead of an Interaktor::Context.
Impacts to normal usage of the gem
- Attempting to access input arguments on an Interaction after the interaction has finished executing will raise
NoMethodError - Attempting to access success arguments on an Interaction after the interaction has finished executing, having resulted in a failure will raise
NoMethodError - Attempting to access failure arguments on an Interaction after the interaction has finished executing, having resulted in a success will raise
NoMethodError - Calling an interaktor with any input arguments that are not explicitly defined as input arguments on the interaktor class will now raise an exception, where previously they would have been silently ignored.
Other impacts which are less likely to impact normal gem usage
- This context object was an
OpenStructwrapper, which is being removed as a default gem in Ruby 3.5, and is also generally recommended to be avoided for performance concerns. The new Interaction class is not an OpenStruct, and OpenStruct is no longer a dependency of this gem. - Organizers have their own interaction instance to track its own input, success, and failure arguments - previously, the same context object would have been passed between the organized interaktors, but that is no longer the case - each organized interaktor creates its own interaction from scratch, based on the prior interaktor's interaction data.
- Attempting to access success or failure arguments on an Interaction before the interaction has finished executing will raise
NoMethodError - Calling
#failure?or#success?on an interaction before the interaction has completed execution will raise an exception
v0.4.0
Added
- An
ensure_hookmethod has been added which will run a piece of code after normal interaktor execution, regardless of whether or not the interaktor ran successfully. The method accepts a symbol (corresponding to an instance method name to call), or a block (containing code to run). These hooks, like others, will run in the order in which they are defined. (@nicolas-heinig, #16)
v0.3.0
Buckle up, we've got some breaking changes.
Fixed
- Some methods that previously raised
NoMethodErrorexceptions now raiseNotImplementedErrorexceptions. This is done in an effort to denote these methods as "abstract" methods.NoMethodErroris a subclass ofExceptionand notStandardErrorso it is generally a bad idea to raise them without understanding the consequences, especially in a library such as this.
Changed
- Attributes of all kinds (input, success, and failure attributes) are now defined using dry-schema's schema DSL. Check out the revised README for more details. This change should prevent me from having to reinvent the wheel for validating attributes in general.
- Organizers now pass their input attributes into all organized interaktors' input attributes.
- Organized interaktors now pass their success attributes into all successive organized interaktors' input attributes.
- For example, when an organizer organizes interaktors A, B, C, and D, in that order, A's success attributes may be used as input attributes of B, C, and D. C's success attributes may be used as input attributes of D.
- Some exception messages are now benefiting from increased excellence.
Added
- Explicit support for Ruby 3.0.
v0.2.0
Fixed
- Interaktors which have success attributes defined will now cause an exception to be raised if their execution finishes completely without a call to
#success!.
Changed
- Organizers now pass their own attributes to the first interaktor, and each interaktor passes its attributes (required, optional, and success) to the next interaktor in the chain. When passing attributes between interaktors, attributes unknown to the receiving interaktor are dropped. See the organizer section of the README for more detail.
- Providing unknown options to the
failureandsuccessDSL methods will now raise an exception. - Passing a non-hash argument to
.callor.call!will raise a more helpful exception.
Added
- Added custom error classes for the various error cases instead of raising
RuntimeErrors.
v0.1.5
Fixed
- Using
#success!to return early from an interaktor should no longer prevent organizers from working properly.
Changed
- An error will now be raised when you call an interaktor and an attribute is provided that is not defined on the interaktor class.
Added
- Added
defaultoption to theoptionalDSL method, which can be optionally provided to set a default value for an optional attribute, which will be set if the attribute is not set when called
v0.1.4
Changed
- Removed the public accessor for
contextnow that the entire interface for an interaktor's context should consist of explicitly defined attributes. This is a breaking change as it is no longer backwards-compatible with Interactor. No major version bump because this is definitely not 1.0 yet, and I can't imagine anyone is using this at this point. - Relaxed zeitwerk dependency version from
~> 2.3.1to~> 2.0
Added
- Added
#success!method for early-exit functionality, and their accompanyingsuccessattribute DSL method
v0.1.3
This is the first public release. It can act as a drop-in replacement for Interactor, assuming you change the module name references to Interaktor.