A service object framework for Rails that encapsulates business logic with input validation and type safety.
ActiveInteraction is a Ruby gem that provides a service object framework for Rails applications. It helps developers encapsulate business logic into discrete, reusable components called interactions, which handle input validation, type coercion, and execution in a structured way. It solves the problem of scattered business logic in controllers and models by promoting separation of concerns and testability.
Rails developers building applications with complex business logic that needs to be organized, tested, and maintained separately from controllers and models. It's particularly useful for teams adopting service-oriented architectures or looking to reduce fat models and controllers.
Developers choose ActiveInteraction because it offers a clean, Rails-native way to implement service objects with built-in validation, type safety, and seamless integration with Rails conventions. Its focus on input filtering and error handling reduces boilerplate and helps prevent bugs, while features like composition and callbacks support scalable application design.
:briefcase: Manage application specific business logic.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses a comprehensive filter system to define and coerce input types like strings, integers, and hashes, ensuring data integrity with automatic error handling before execution.
Seamlessly integrates with Rails controllers, models, and forms, supporting ActiveModel validations and form helpers, making it easy to adopt in existing Rails apps without breaking conventions.
Allows interactions to call other interactions via `compose`, enabling reusable and testable business logic components, as demonstrated in the advanced usage section.
Provides detailed errors with symbols for easy testing and supports merging errors from ActiveRecord models, improving debuggability and error management.
Introduces its own DSL for filters and callbacks, which can add a learning curve and boilerplate code, especially for simple operations that don't benefit from such structure.
Heavily dependent on Rails conventions and ActiveSupport, with filters like 'record' assuming ActiveRecord, limiting flexibility in non-Rails environments or with alternative ORMs.
As admitted in the README, composed interactions can lead to misleading error messages when inputs have the same name, requiring careful handling to avoid confusion.