Module: Preferable::Model::ClassMethods

Defined in:
lib/preferable/model.rb

Instance Method Summary collapse

Instance Method Details

#preferable(&block) ⇒ Object

Preferable definition for a model. Example:

class User < ActiveRecord::Base

  preferable do
    integer :theme_id
    boolean :accessible, :default => false
    string  :font_color, :default => "444444", :if => lambda {|value| value =~ /^[A-F0-9]{6}$/ }
  end

end


23
24
25
26
27
28
29
30
31
# File 'lib/preferable/model.rb', line 23

def preferable(&block)
  unless _preferable
    self._preferable = Preferable::Schema.new
    serialize :preferences
    include PreferableMethods
  end
  self._preferable.instance_eval(&block) if block
  self._preferable
end