Class: Anemone::Storage::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/anemone/storage/base.rb

Instance Method Summary collapse

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

#closeObject



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

#eachObject



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

Returns:

  • (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

#keysObject



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

#sizeObject



55
56
57
58
59
# File 'lib/anemone/storage/base.rb', line 55

def size
  @adap.size
  rescue
    raise GenericError, $!
end