Class: Medusa::Storage::Base
- Inherits:
-
Object
- Object
- Medusa::Storage::Base
- Defined in:
- lib/medusa/storage/base.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ 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/medusa/storage/base.rb', line 7 def initialize(adapter) @adap = adapter # verify adapter conforms to this class's methods public_methods(false).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 |
# File 'lib/medusa/storage/base.rb', line 18 def [](key) @adap[key] rescue raise RetrievalError end |
#[]=(key, value) ⇒ Object
24 25 26 27 28 |
# File 'lib/medusa/storage/base.rb', line 24 def []=(key, value) @adap[key] = value rescue raise InsertionError end |
#clear ⇒ Object
36 37 38 39 40 |
# File 'lib/medusa/storage/base.rb', line 36 def clear @adap.clear rescue raise GenericError end |
#close ⇒ Object
54 55 56 57 58 |
# File 'lib/medusa/storage/base.rb', line 54 def close @adap.close rescue raise CloseError end |
#delete(key) ⇒ Object
30 31 32 33 34 |
# File 'lib/medusa/storage/base.rb', line 30 def delete(key) @adap.delete(key) rescue raise DeletionError end |
#each ⇒ Object
42 43 44 45 46 |
# File 'lib/medusa/storage/base.rb', line 42 def each @adap.each { |k, v| yield k, v } rescue raise GenericError end |
#has_key?(key) ⇒ Boolean
72 73 74 75 76 |
# File 'lib/medusa/storage/base.rb', line 72 def has_key?(key) @adap.has_key?(key) rescue raise GenericError end |
#keys ⇒ Object
66 67 68 69 70 |
# File 'lib/medusa/storage/base.rb', line 66 def keys @adap.keys rescue raise GenericError end |
#merge!(hash) ⇒ Object
48 49 50 51 52 |
# File 'lib/medusa/storage/base.rb', line 48 def merge!(hash) @adap.merge!(hash) rescue raise GenericError end |
#size ⇒ Object
60 61 62 63 64 |
# File 'lib/medusa/storage/base.rb', line 60 def size @adap.size rescue raise GenericError end |