Module: CouchTomato::Persistence::Properties::ClassMethods

Defined in:
lib/couch_tomato/persistence/properties.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(name) ⇒ Object

:nodoc:



51
52
53
# File 'lib/couch_tomato/persistence/properties.rb', line 51

def belongs_to(name) #:nodoc:
  property name, :class => BelongsToProperty
end

#json_create(json, meta = {}) ⇒ Object

:nodoc:



30
31
32
33
34
35
36
# File 'lib/couch_tomato/persistence/properties.rb', line 30

def json_create(json, meta={}) #:nodoc:
  return if json.nil?
  instance = super
  # instance.send(:assign_attribute_copies_for_dirty_tracking)
  instance. = meta
  instance
end

#property(name, options = {}) ⇒ Object

Declare a proprty on a model class. properties are not typed by default. You can use any of the basic types by JSON (String, Integer, Fixnum, Array, Hash). If you want a property to be of a custom class you have to define it using the :class option.

example:

class Book
  property :title
  property :year
  property :publisher, :class => Publisher
end


46
47
48
49
# File 'lib/couch_tomato/persistence/properties.rb', line 46

def property(name, options = {})
  clazz = options.delete(:class)
  properties << (clazz || SimpleProperty).new(self, name, options)
end

#property_namesObject

returns all the property names of a model class that have been defined using the #property method

example:

class Book
  property :title
  property :year
end
Book.property_names # => [:title, :year]


26
27
28
# File 'lib/couch_tomato/persistence/properties.rb', line 26

def property_names
  properties.map(&:name)
end