Module: Ork::Document
- Defined in:
- lib/ork/model/document.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Check for equality by doing the following assertions:.
-
#delete ⇒ Object
Delete the model.
- #embeddable? ⇒ Boolean
-
#inspect ⇒ Object
Pretty print for the model.
- #new? ⇒ Boolean
-
#reload ⇒ Object
Preload all the attributes of this model from Riak.
-
#save ⇒ Object
Persist the model attributes and update indices and unique indices.
-
#update(attributes) ⇒ Object
Update the model attributes and call save.
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/ork/model/document.rb', line 6 def id @id end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Check for equality by doing the following assertions:
-
That the passed model is of the same type.
-
That they represent the same RObject id.
18 19 20 |
# File 'lib/ork/model/document.rb', line 18 def ==(other) other.kind_of?(model) && other.id == id end |
#delete ⇒ Object
Delete the model
91 92 93 94 95 96 |
# File 'lib/ork/model/document.rb', line 91 def delete __robject.delete unless new? freeze rescue Riak::FailedRequest false end |
#embeddable? ⇒ Boolean
27 28 29 |
# File 'lib/ork/model/document.rb', line 27 def false end |
#inspect ⇒ Object
Pretty print for the model
Example:
User.new(name: 'John').inspect
# => #<User:6kS5VHNbaed9h7gFLnVg5lmO4U7 {:name=>"John"}>
37 38 39 |
# File 'lib/ork/model/document.rb', line 37 def inspect "#<#{model}:#{id || 'nil'} #{attributes.inspect}>" end |
#new? ⇒ Boolean
23 24 25 |
# File 'lib/ork/model/document.rb', line 23 def new? !id end |
#reload ⇒ Object
Preload all the attributes of this model from Riak.
86 87 88 |
# File 'lib/ork/model/document.rb', line 86 def reload new? ? self : self.load!(@id) end |
#save ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ork/model/document.rb', line 72 def save __robject.content_type = model.content_type __robject.data = __persist_attributes __check_unique_indices __update_indices __robject.store @id = __robject.key self end |
#update(attributes) ⇒ Object
Update the model attributes and call save.
Example:
User[1].update(:name => "John")
# It's the same as:
u = User[1]
u.update_attributes(:name => "John")
u.save
53 54 55 56 |
# File 'lib/ork/model/document.rb', line 53 def update(attributes) update_attributes(attributes) save end |