module Riagent::Persistence::ClassMethods
Public Instance Methods
all(results_limit=1000)
click to toggle source
Return all the documents in the collection @param [Integer] results_limit Number of results returned @return [Array|nil] of ActiveDocument
instances
# File lib/riagent/persistence.rb, line 105 def all(results_limit=1000) self.persistence.all(results_limit) end
collection_type(coll_type, options={})
click to toggle source
Set the document’s persistence strategy Usage: <code> class SomeModel
include Riagent::ActiveDocument collection_type :riak_kv, # Persist to a Riak::Bucket list_keys_using: :riak_dt_set #keep track of keys in a Set CRDT data type
end </code>
# File lib/riagent/persistence.rb, line 118 def collection_type(coll_type, options={}) 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_kv self.persistence = Riagent::Persistence::RiakKVStrategy.new(self) if options.has_key? :list_keys_using if options[:list_keys_using] == :streaming_list_keys self.persistence = Riagent::Persistence::RiakNoIndexStrategy.new(self) elsif options[:list_keys_using] == :riak_dt_set self.persistence = Riagent::Persistence::RiakDTSetStrategy.new(self) end end end end
find(key)
click to toggle source
Load a document by key.
# File lib/riagent/persistence.rb, line 137 def find(key) return nil if key.nil? or key.empty? self.persistence.find(key) end
find_one(query)
click to toggle source
Return the first document that matches the query
# File lib/riagent/persistence.rb, line 143 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()
click to toggle source
# File lib/riagent/persistence.rb, line 150 def get_collection_type @collection_type ||= nil end
persistence()
click to toggle source
# File lib/riagent/persistence.rb, line 154 def persistence @persistence ||= nil end
persistence=(persistence_strategy)
click to toggle source
# File lib/riagent/persistence.rb, line 158 def persistence=(persistence_strategy) @persistence = persistence_strategy end
where(query)
click to toggle source
Return all documents that match the query
# File lib/riagent/persistence.rb, line 163 def where(query) unless self.persistence.allows_query? raise NotImplementedError, "This collection type does not support querying" end self.persistence.where(query) end