Behave as ActiveRecord. Why do we want objects to be AR lookalikes?
You may love ActiveRecord, or you may hate ActiveRecord, but please be honest: it allows us to make our code amazing. And it’s indispensable in Rails now.
In addition to the constantly evolving ORM system, ActiveRecord is gaining many features that are well integrated into Rails. Therefore, we decided that Tramway Decorator and Tramway Form should contain some of those features. Cause we want to write amazing code still with Tramway!
For now, decorated and form becomes “imposter” in these cases:
- Arguments in Rails routes helpers
@user = tramway_decorate User.first
redirect user_path @user
2. Serializable objects
@user = tramway_decorate User.first
render json: @user, serializer: UserSerializer
3. Actionable objects (it does not work by default, you must use behave_as_ar
method inside the decorator or form)
@user = tramway_form User.first
@user.update params
# OR
@user.destroy
You can find details here.
What do you think about this “imposter” stuff? :)