Class: Moneta::Adapters::MongoBase Private
- Inherits:
-
Object
- Object
- Moneta::Adapters::MongoBase
- Includes:
- Defaults, ExpiresSupport
- Defined in:
- lib/moneta/adapters/mongo/base.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_PORT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
27017
Instance Attribute Summary collapse
- #backend ⇒ Object readonly private
Attributes included from ExpiresSupport
Instance Method Summary collapse
-
#fetch_values(*keys, **options) ⇒ Object
Behaves identically to #values_at except that it accepts an optional block.
-
#initialize(options = {}) ⇒ MongoBase
constructor
private
A new instance of MongoBase.
-
#values_at(*keys, **options) ⇒ Array<Object, nil>
Returns an array containing the values associated with the given keys, in the same order as the supplied keys.
Methods included from ExpiresSupport
Methods included from Defaults
#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, included, #increment, #key?, #merge!, #slice, #supports?, #update
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ MongoBase
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MongoBase.
15 16 17 18 19 20 |
# File 'lib/moneta/adapters/mongo/base.rb', line 15 def initialize( = {}) self.default_expires = .delete(:expires) @expires_field = .delete(:expires_field) || 'expiresAt' @value_field = .delete(:value_field) || 'value' @type_field = .delete(:type_field) || 'type' end |
Instance Attribute Details
#backend ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/moneta/adapters/mongo/base.rb', line 11 def backend @backend end |
Instance Method Details
#fetch_values(*keys, **options) ⇒ Object #fetch_values(*keys, **options) {|key| ... } ⇒ Array<Object, nil>
Some adapters may implement this method atomically. The default implmentation uses #values_at.
Behaves identically to #values_at except that it accepts an optional block. When supplied, the block will be called successively with each supplied key that is not present in the store. The return value of the block call will be used in place of nil in returned the array of values.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/moneta/adapters/mongo/base.rb', line 23 def fetch_values(*keys, **) return values_at(*keys, **) unless block_given? hash = Hash[slice(*keys, **)] keys.map do |key| if hash.key?(key) hash[key] else yield key end end end |
#values_at(*keys, **options) ⇒ Array<Object, nil>
Some adapters may implement this method atomically, but the default implementation simply makes repeated calls to #load.
Returns an array containing the values associated with the given keys, in the same order as the supplied keys. If a key is not present in the key-value-store, nil is returned in its place.
36 37 38 39 |
# File 'lib/moneta/adapters/mongo/base.rb', line 36 def values_at(*keys, **) hash = Hash[slice(*keys, **)] keys.map { |key| hash[key] } end |