activerecord-utils
activerecord-utils gem - utilities (e.g. random, alias_attr, etc.) for activerecord in ruby
- home :: github.com/rubylibs/activerecord-utils
- bugs :: github.com/rubylibs/activerecord-utils/issues
- gem :: rubygems.org/gems/activerecord-utils
- rdoc :: rubydoc.info/gems/activerecord-utils
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
random_recordgem - (Source) returns a random record for Ruby Models using ActiveRecordactiverecord_randomgem - (Source) empowers your ActiveRecord Models with the ability to return a random record without using SQL RAND()randomizrgem - Returns one random Active Record object using cross-platform ANSI compliant SQLfast_randomgem - (Source) ultra fast order by rand() solutionrandumb- adds ability to pull back random records from Active Record
License
The scripts are dedicated to the public domain. Use it as you please with no restrictions whatsoever.