Project

cymbalize

0.0
No commit activity in last 3 years
No release in over 3 years
Cymbalize is a tiny extension to support symbolized columns in ActiveRecord, with optional convenience methods. It's heavily inspired by nofxx's symbolize Gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.11.0
>= 1.3.6

Runtime

>= 3.0.0
>= 3.0.0
 Project Readme

cymbalize

Use symbols in ActiveRecord columns. This gem implements a subset of nofxx's symbolize gem.

Installation

Include the gem in your Gemfile:

gem 'cymbalize', '~> 0.1.0'

Features

Please note that :scopes, :methods, and :allow_blank don't do anything unless :in is an array with at least one symbol.

Symbolize a column with symbolize

class User < ActiveRecord::Base
  symbolize :gender
end

u = User.new(:gender => :robot)
u.gender # :robot

Add a list of valid values with :in

class User < ActiveRecord::Base
  symbolize :gender, :in => [:decepticon, :autobot]
end

u = User.new(:gender => :autobot)
u.valid? # true
u.gender = :robot
u.valid? # false

Add boolean methods with :methods

class User < ActiveRecord::Base
  symbolize :gender, :in => [:asterix, :obelix], :methods => true
end

u = User.new(:gender => :asterix)
u.asterix? # true
u.obelix? # false

Add ActiveRecord scopes with :scopes

class User < ActiveRecord::Base
  symbolize :gender, :in => [:zerg, :protoss, :terran], :scopes => true
end

u = User.create(:gender => :zerg)
User.zerg.include?(u) # true
User.protoss.include?(u) # false

Allow blank values with :allow_blank

class User < ActiveRecord::Base
  symbolize :gender, :in => [:mod, :rocker], :allow_blank => true
end

u = User.new(:gender => nil)
u.valid? # true
u.gender # nil

u.gender = ''
u.valid? # true
u.gender # nil