0.0
No commit activity in last 3 years
No release in over 3 years
Custom serializable ActiveModel object.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 4.2.0
>= 0.13.1
>= 0
>= 0.3.8

Runtime

>= 3.0.0
 Project Readme

vinaigrette

vinaigrette is a gem providing a custom ActiveModel object that can be used as a serialized attribute of an ActiveRecord object.

Features

  • Serializable ActiveModel objects.
  • Custom accessors with casting support default values.
  • Support for Rails validations.
  • Support for Rails belongs_to associations.
  • Casting of ruby booleans from strings.

Installation

Add this line to your application's Gemfile:

gem 'vinaigrette'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vinaigrette

Usage

Create a custom Vinaigrette::Base subclass:

class AnethSauce < Vinaigrette::Base
end

Add your attributes using vinaigrette_accessor:

# Simple string attribute
vinaigrette_accessor :name, String

# With a default value
vinaigrette_accessor :description, String, "Nothing here!"

# A Boolean
vinaigrette_accessor :spicy?, "Boolean", false

# With support for callables
vinaigrette_accessor :secret, String, lambda { something_secret }

# You can also create belongs_to associations
vinaigrette_accessor :sauce_id, Integer
belongs_to :sauce

Use vinaigrette_serialize method to include it in your ActiveRecord object:

class SalmonDish < ActiveRecord::Base
    include Vinaigrette::Serialize

    ...

    vinaigrette_serialize :sauce, AnethSauce
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request