Module: Riik::Document
- Defined in:
- lib/riik/document.rb,
lib/riik/document/finders.rb,
lib/riik/document/persistence.rb
Overview
Document is the base object for the Riik ORM. Including it provides the basic functionality for assigning attributes to models, assigning a bucket name, and serializing objects.
Defined Under Namespace
Modules: ClassMethods, Finders, Persistence
Instance Attribute Summary collapse
-
#robject ⇒ Riak::RObject
Create or return the current Riak client object.
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ Hash
Serialize the attributes of this model.
-
#bucket ⇒ Riak::Bucket
Return the bucket for this class.
-
#initialize(attributes = {}) ⇒ Object
Assign model attributes through initialization hash.
-
#key ⇒ String
Delegate the object key to the Riak object.
-
#riik_attributes ⇒ Array
Return the riik attribute list for this class.
Instance Attribute Details
#robject ⇒ Riak::RObject
Create or return the current Riak client object.
102 103 104 |
# File 'lib/riik/document.rb', line 102 def robject @robject end |
Class Method Details
.included(base) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/riik/document.rb', line 11 def self.included(base) base.send :extend, ClassMethods base.send :include, Finders base.send :include, Persistence end |
Instance Method Details
#attributes ⇒ Hash
Serialize the attributes of this model.
71 72 73 |
# File 'lib/riik/document.rb', line 71 def attributes Hash[riik_attributes.zip(riik_attributes.map { |attr| instance_variable_get "@#{attr}" })] end |
#bucket ⇒ Riak::Bucket
Return the bucket for this class.
88 89 90 |
# File 'lib/riik/document.rb', line 88 def bucket self.class.bucket end |
#initialize(attributes = {}) ⇒ Object
Assign model attributes through initialization hash.
58 59 60 61 62 63 64 |
# File 'lib/riik/document.rb', line 58 def initialize(attributes = {}) attributes.symbolize_keys.each do |key, value| if riik_attributes.include?(key) instance_variable_set "@#{key}", value end end end |
#key ⇒ String
Delegate the object key to the Riak object.
96 97 98 |
# File 'lib/riik/document.rb', line 96 def key robject.key end |
#riik_attributes ⇒ Array
Return the riik attribute list for this class.
80 81 82 |
# File 'lib/riik/document.rb', line 80 def riik_attributes self.class.riik_attributes end |