Module: Riagent::Persistence::ClassMethods
- Defined in:
- lib/riagent/persistence.rb
Instance Method Summary collapse
-
#all(results_limit = 1000) ⇒ Array|nil
Return all the documents in the collection.
-
#collection_type(coll_type, options = {}) ⇒ Object
Set the document’s persistence strategy Usage:
class SomeModel include Riagent::ActiveDocument collection_type :riak_json # persist to a RiakJson::Collection end. -
#find(key) ⇒ Object
Load a document by key.
-
#find_one(query) ⇒ Object
Return the first document that matches the query.
- #get_collection_type ⇒ Object
- #persistence ⇒ Object
- #persistence=(persistence_strategy) ⇒ Object
-
#where(query) ⇒ Object
Return all documents that match the query.
Instance Method Details
#all(results_limit = 1000) ⇒ Array|nil
Return all the documents in the collection
107 108 109 |
# File 'lib/riagent/persistence.rb', line 107 def all(results_limit=1000) self.persistence.all(results_limit) end |
#collection_type(coll_type, options = {}) ⇒ Object
Set the document’s persistence strategy Usage: <code> class SomeModel
include Riagent::ActiveDocument
collection_type :riak_json # persist to a RiakJson::Collection
end </code>
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/riagent/persistence.rb', line 119 def collection_type(coll_type, ={}) unless COLLECTION_TYPES.include? coll_type raise ArgumentError, "Invalid collection type: #{coll_type.to_s}" end @collection_type = coll_type case @collection_type when :riak_json self.persistence = Riagent::Persistence::RiakJsonStrategy.new(self) when :riak_kv self.persistence = Riagent::Persistence::RiakKVStrategy.new(self) if .has_key? :list_keys_using if [:list_keys_using] == :streaming_list_keys self.persistence = Riagent::Persistence::RiakNoIndexStrategy.new(self) elsif [:list_keys_using] == :riak_dt_set self.persistence = Riagent::Persistence::RiakDTSetStrategy.new(self) end end end end |
#find(key) ⇒ Object
Load a document by key.
140 141 142 143 |
# File 'lib/riagent/persistence.rb', line 140 def find(key) return nil if key.nil? or key.empty? self.persistence.find(key) end |
#find_one(query) ⇒ Object
Return the first document that matches the query
146 147 148 149 150 151 |
# File 'lib/riagent/persistence.rb', line 146 def find_one(query) unless self.persistence.allows_query? raise NotImplementedError, "This collection type does not support querying" end self.persistence.find_one(query) end |
#get_collection_type ⇒ Object
153 154 155 |
# File 'lib/riagent/persistence.rb', line 153 def get_collection_type @collection_type ||= nil end |
#persistence ⇒ Object
157 158 159 |
# File 'lib/riagent/persistence.rb', line 157 def persistence @persistence ||= nil end |
#persistence=(persistence_strategy) ⇒ Object
161 162 163 |
# File 'lib/riagent/persistence.rb', line 161 def persistence=(persistence_strategy) @persistence = persistence_strategy end |
#where(query) ⇒ Object
Return all documents that match the query
166 167 168 169 170 171 |
# File 'lib/riagent/persistence.rb', line 166 def where(query) unless self.persistence.allows_query? raise NotImplementedError, "This collection type does not support querying" end self.persistence.where(query) end |