Class: CMDB::Source::Memory
- Inherits:
-
Object
- Object
- CMDB::Source::Memory
- Defined in:
- lib/cmdb/source/memory.rb
Overview
Data source that is backed by the an in-memory Ruby hash; used solely for testing.
Instance Attribute Summary collapse
-
#prefix ⇒ String
readonly
The empty string.
Instance Method Summary collapse
-
#each_pair {|name, value| ... } ⇒ Object
Enumerate the keys in this source, and their values.
-
#get(key) ⇒ nil, ...
Get the value of key.
-
#initialize(hash, prefix) ⇒ Memory
constructor
Construct a new Source::Memory.
-
#set(key, value) ⇒ Object
Set the value of a key.
Constructor Details
#initialize(hash, prefix) ⇒ Memory
Construct a new Source::Memory.
12 13 14 15 16 |
# File 'lib/cmdb/source/memory.rb', line 12 def initialize(hash, prefix) uri = URI.parse("memory:#{hash.object_id}") super(uri, prefix) @hash = hash end |
Instance Attribute Details
#prefix ⇒ String (readonly)
Returns the empty string.
9 10 11 |
# File 'lib/cmdb/source/memory.rb', line 9 def prefix @prefix end |
Instance Method Details
#each_pair {|name, value| ... } ⇒ Object
Enumerate the keys in this source, and their values.
36 37 38 |
# File 'lib/cmdb/source/memory.rb', line 36 def each_pair(&block) @hash.each_pair(&block) end |
#get(key) ⇒ nil, ...
Get the value of key.
21 22 23 |
# File 'lib/cmdb/source/memory.rb', line 21 def get(key) @hash[key] end |
#set(key, value) ⇒ Object
Set the value of a key.
26 27 28 29 |
# File 'lib/cmdb/source/memory.rb', line 26 def set(key, value) value = JSON.dump(value) unless value.is_a?(String) @hash[key] = value end |