An array of all of the model's frozen instances, without issuing a database query.
# File lib/sequel/plugins/static_cache.rb, line 34 def all @all.dup end
Return the frozen object with the given pk, or nil if no such object exists in the cache, without issuing a database query.
# File lib/sequel/plugins/static_cache.rb, line 49 def cache_get_pk(pk) cache[pk] end
Get the number of records in the cache, without issuing a database query.
# File lib/sequel/plugins/static_cache.rb, line 39 def count(*a, &block) if a.empty? && !block @all.size else super end end
Yield each of the model's frozen instances to the block, without issuing a database query.
# File lib/sequel/plugins/static_cache.rb, line 55 def each(&block) @all.each(&block) end
Use the cache instead of a query to get the results.
# File lib/sequel/plugins/static_cache.rb, line 60 def map(column=nil, &block) if column raise(Error, "Cannot provide both column and block to map") if block if column.is_a?(Array) @all.map{|r| r.values.values_at(*column)} else @all.map{|r| r[column]} end else @all.map(&(Proc.new if block_given?)) end end
Use the cache instead of a query to get the results.
# File lib/sequel/plugins/static_cache.rb, line 76 def to_hash(key_column = nil, value_column = nil) return cache.dup if key_column.nil? && value_column.nil? h = {} if value_column if value_column.is_a?(Array) if key_column.is_a?(Array) each{|r| h[r.values.values_at(*key_column)] = r.values.values_at(*value_column)} else each{|r| h[r[key_column]] = r.values.values_at(*value_column)} end else if key_column.is_a?(Array) each{|r| h[r.values.values_at(*key_column)] = r[value_column]} else each{|r| h[r[key_column]] = r[value_column]} end end elsif key_column.is_a?(Array) each{|r| h[r.values.values_at(*key_column)] = r} else each{|r| h[r[key_column]] = r} end h end
Use the cache instead of a query to get the results
# File lib/sequel/plugins/static_cache.rb, line 103 def to_hash_groups(key_column, value_column = nil) h = {} if value_column if value_column.is_a?(Array) if key_column.is_a?(Array) each{|r| (h[r.values.values_at(*key_column)] ||= []) << r.values.values_at(*value_column)} else each{|r| (h[r[key_column]] ||= []) << r.values.values_at(*value_column)} end else if key_column.is_a?(Array) each{|r| (h[r.values.values_at(*key_column)] ||= []) << r[value_column]} else each{|r| (h[r[key_column]] ||= []) << r[value_column]} end end elsif key_column.is_a?(Array) each{|r| (h[r.values.values_at(*key_column)] ||= []) << r} else each{|r| (h[r[key_column]] ||= []) << r} end h end
Generated with the Darkfish Rdoc Generator 2.