ActiveModel – Making Ruby Classes Behave Like Models

Share:

Listens: 0

Rails Coach

Technology


I’ve been working on an ORM for Cassandra. One of the things I’ve been using to build the ORM is ActiveModel. ActiveModel gives you modules you can add to your class that makes it behave like an ActiveRecord Model. Here are some of the features you can add to your classes with ActiveModel. Attribute Methods Callbacks Dirty Attributes (knowing which attributes have changed) Naming (allows you to reference the class and model by the object) Observers Serialization (to JSON or XML) State Machine (a really basic one) Translation Validations So, if you’re looking to add your Ruby class to a Rails app, or want this sort of behavior in Sinatra, etc. this is a great way to get it.