Module: CouchPotato::Persistence::Properties::ClassMethods
- Defined in:
- lib/couch_potato/persistence/properties.rb
Instance Method Summary collapse
-
#json_create(json) ⇒ Object
:nodoc:.
-
#property(name, options = {}) ⇒ Object
Declare a property on a model class.
-
#property_names ⇒ Object
returns all the property names of a model class that have been defined using the #property method.
Instance Method Details
#json_create(json) ⇒ Object
:nodoc:
62 63 64 65 66 67 |
# File 'lib/couch_potato/persistence/properties.rb', line 62 def json_create(json) #:nodoc: return if json.nil? instance = super instance.send(:assign_attribute_copies_for_dirty_tracking) instance end |
#property(name, options = {}) ⇒ Object
Declare a property on a model class. Properties are not typed by default. You can store anything in a property that can be serialized into JSON. If you want a property to be of a custom class you have to define it using the :type option.
example:
class Book
property :title
property :year
property :publisher, :type => Publisher
end
79 80 81 |
# File 'lib/couch_potato/persistence/properties.rb', line 79 def property(name, = {}) properties << SimpleProperty.new(self, name, ) end |
#property_names ⇒ Object
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]
58 59 60 |
# File 'lib/couch_potato/persistence/properties.rb', line 58 def property_names properties.map(&:name) end |