Module: CouchPotato::Persistence
- Defined in:
- lib/couch_potato/persistence.rb,
lib/couch_potato/persistence/json.rb,
lib/couch_potato/persistence/callbacks.rb,
lib/couch_potato/persistence/properties.rb,
lib/couch_potato/persistence/simple_property.rb,
lib/couch_potato/persistence/dirty_attributes.rb,
lib/couch_potato/persistence/inline_collection.rb,
lib/couch_potato/persistence/belongs_to_property.rb
Defined Under Namespace
Modules: Callbacks, DirtyAttributes, Json, Properties
Classes: BelongsToProperty, InlineCollection, SimpleProperty
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/couch_potato/persistence.rb', line 15
def self.included(base)
base.send :include, Properties, Callbacks, Validatable, Json, CouchPotato::View::CustomViews
base.send :include, DirtyAttributes
base.send :include, MagicTimestamps
base.class_eval do
attr_accessor :_id, :_rev, :_attachments, :_deleted
alias_method :id, :_id
end
end
|
Instance Method Details
#==(other) ⇒ Object
52
53
54
|
# File 'lib/couch_potato/persistence.rb', line 52
def ==(other)
other.class == self.class && self.to_json == other.to_json
end
|
#attributes ⇒ Object
37
38
39
40
41
42
|
# File 'lib/couch_potato/persistence.rb', line 37
def attributes
self.class.properties.inject({}) do |res, property|
property.serialize(res, self)
res
end
end
|
#attributes=(hash) ⇒ Object
31
32
33
34
35
|
# File 'lib/couch_potato/persistence.rb', line 31
def attributes=(hash)
hash.each do |attribute, value|
self.send "#{attribute}=", value
end
end
|
#initialize(attributes = {}) ⇒ Object
25
26
27
28
29
|
# File 'lib/couch_potato/persistence.rb', line 25
def initialize(attributes = {})
attributes.each do |name, value|
self.send("#{name}=", value)
end if attributes
end
|
#new? ⇒ Boolean
44
45
46
|
# File 'lib/couch_potato/persistence.rb', line 44
def new?
_rev.nil?
end
|
#to_param ⇒ Object
48
49
50
|
# File 'lib/couch_potato/persistence.rb', line 48
def to_param
_id
end
|