Class: Anemone::Storage::Base
- Inherits:
-
Object
- Object
- Anemone::Storage::Base
- Defined in:
- lib/anemone/storage/base.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #close ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(adapter) ⇒ Base
constructor
A new instance of Base.
- #keys ⇒ Object
- #merge!(hash) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(adapter) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/anemone/storage/base.rb', line 7 def initialize(adapter) @adap = adapter # verify adapter conforms to this class's methods methods.each do |method| if !@adap.respond_to?(method.to_sym) raise "Storage adapter must support method #{method}" end end end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/anemone/storage/base.rb', line 18 def [](key) @adap[key] rescue puts key raise RetrievalError, $! end |
#[]=(key, value) ⇒ Object
25 26 27 28 29 |
# File 'lib/anemone/storage/base.rb', line 25 def []=(key, value) @adap[key] = value rescue raise InsertionError, $! end |
#close ⇒ Object
49 50 51 52 53 |
# File 'lib/anemone/storage/base.rb', line 49 def close @adap.close rescue raise CloseError, $! end |
#delete(key) ⇒ Object
31 32 33 34 35 |
# File 'lib/anemone/storage/base.rb', line 31 def delete(key) @adap.delete(key) rescue raise DeletionError, $! end |
#each ⇒ Object
37 38 39 40 41 |
# File 'lib/anemone/storage/base.rb', line 37 def each @adap.each { |k, v| yield k, v } rescue raise GenericError, $! end |
#has_key?(key) ⇒ Boolean
67 68 69 70 71 |
# File 'lib/anemone/storage/base.rb', line 67 def has_key?(key) @adap.has_key?(key) rescue raise GenericError, $! end |
#keys ⇒ Object
61 62 63 64 65 |
# File 'lib/anemone/storage/base.rb', line 61 def keys @adap.keys rescue raise GenericError, $! end |
#merge!(hash) ⇒ Object
43 44 45 46 47 |
# File 'lib/anemone/storage/base.rb', line 43 def merge!(hash) @adap.merge!(hash) rescue raise GenericError, $! end |
#size ⇒ Object
55 56 57 58 59 |
# File 'lib/anemone/storage/base.rb', line 55 def size @adap.size rescue raise GenericError, $! end |