activerecord-utils

activerecord-utils gem - utilities (e.g. random, alias_attr, etc.) for activerecord in ruby

Usage

alias_attr macro

alias_attr  :plato, :og         # new, old

generates

def plato                 # reader
  send( :og )             #  e.g. return og
end

def plato=(value)         # writer
  send( :'og=', value )   #  e.g. return self.og=value
end

attr_reader_w_fallback macro

attr_reader_w_fallbacks :published, :touched

generates

def published
  read_attribute_w_fallbacks( :published, :touched )
end

'rnd' finder

e.g. find random record e.g.

beer_of_the_week = Beer.rnd

equals

beer_of_the_week = Beer.offset( rand( Beer.count) ).limit(1).first

Alternatives

Random

License

The scripts are dedicated to the public domain. Use it as you please with no restrictions whatsoever.