Module: Moneta::CreateSupport Private
- Included in:
- Adapters::DBM, Adapters::Daybreak, Adapters::GDBM, Adapters::LRUHash, Adapters::LevelDB, Adapters::Memory, Adapters::SDBM, Adapters::TokyoCabinet, WeakCreate
- Defined in:
- lib/moneta/create_support.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Implements simple create using key? and store.
This is sufficient for non-shared stores or if atomicity is not required.
Class Method Summary collapse
- .included(base) ⇒ Object private
Instance Method Summary collapse
-
#create(key, value, options = {}) ⇒ Boolean
Atomically sets a key to value if it’s not set.
Class Method Details
.included(base) ⇒ Object
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.
17 18 19 |
# File 'lib/moneta/create_support.rb', line 17 def self.included(base) base.supports(:create) if base.respond_to?(:supports) end |
Instance Method Details
#create(key, value, options = {}) ⇒ Boolean
Note:
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically sets a key to value if it’s not set.
8 9 10 11 12 13 14 15 |
# File 'lib/moneta/create_support.rb', line 8 def create(key, value, = {}) if key? key false else store(key, value, ) true end end |