No release in over a year
Extension for ActiveRecord to get serializable and marshalizable models using Rasti::Model
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
~> 5.0, < 5.11
~> 0.2
~> 12.3
~> 0.12
~> 1.3.6

Runtime

 Project Readme

ActiveRecord::Serializable

Gem Version CI Coverage Status Code Climate

Extension for ActiveRecord to get serializable and marshalizable models using Rasti::Model

Installation

Add this line to your application's Gemfile:

gem 'active_record-serializable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_record-serializable

Usage

class User < ActiveRecord::Base
  has_one :avatar
  has_many :posts
end

Basic

user = User.find 1
user.to_serializable # ActiveRecord::Serializable::USER[id: 1, ...]

Include relations

user = User.find 1
user.to_serializable include: [:avatar, :posts] # ActiveRecord::Serializable::USER[id: 1, avatar: ActiveRecord::Serializable::AVATAR[...], posts: [ActiveRecord::Serializable::POST[...]]]

Extended with methods

class User < ActiveRecord::Base
  serializable_define_method :sorted_post_titles do
    posts.map(&:title).sort
  end
end

user = User.find 1
serializable = user.to_serializable(include: [:posts])
serializable.sorted_post_titles # ['Title 1', ...]

Extended with modules

module Helper
  def sorted_post_titles
    posts.map(&:title).sort
  end
end

class User < ActiveRecord::Base
  serializable_include Helper
end

user = User.find 1
serializable = user.to_serializable(include: [:posts])
serializable.sorted_post_titles # ['Title 1', ...]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/active_record-serializable.

License

The gem is available as open source under the terms of the MIT License.