Class: FakeSQS::FileDatabase
- Inherits:
-
Object
- Object
- FakeSQS::FileDatabase
- Defined in:
- lib/fake_sqs/file_database.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(filename) ⇒ FileDatabase
constructor
A new instance of FileDatabase.
- #load ⇒ Object
- #reset ⇒ Object
- #select(&block) ⇒ Object
- #transaction ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(filename) ⇒ FileDatabase
Returns a new instance of FileDatabase.
8 9 10 11 |
# File 'lib/fake_sqs/file_database.rb', line 8 def initialize(filename) @filename = filename @queue_objects = {} end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/fake_sqs/file_database.rb', line 6 def filename @filename end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/fake_sqs/file_database.rb', line 36 def [](key) value = storage[key] if value deserialize(key) else value end end |
#[]=(key, value) ⇒ Object
32 33 34 |
# File 'lib/fake_sqs/file_database.rb', line 32 def []=(key, value) storage[key] = value.to_yaml end |
#delete(key) ⇒ Object
58 59 60 |
# File 'lib/fake_sqs/file_database.rb', line 58 def delete(key) storage.delete(key) end |
#each(&block) ⇒ Object
45 46 47 48 49 |
# File 'lib/fake_sqs/file_database.rb', line 45 def each(&block) storage.each do |key, value| yield key, deserialize(key) end end |
#load ⇒ Object
13 14 15 16 17 |
# File 'lib/fake_sqs/file_database.rb', line 13 def load transaction do store["queues"] ||= {} end end |
#reset ⇒ Object
25 26 27 28 29 30 |
# File 'lib/fake_sqs/file_database.rb', line 25 def reset transaction do store["queues"] = {} end @queue_objects = {} end |
#select(&block) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/fake_sqs/file_database.rb', line 51 def select(&block) new_list = storage.select do |key, value| yield key, deserialize(key) end Hash[new_list.map { |key, value| [key, deserialize(key)] }] end |
#transaction ⇒ Object
19 20 21 22 23 |
# File 'lib/fake_sqs/file_database.rb', line 19 def transaction store.transaction do yield end end |
#values ⇒ Object
62 63 64 65 66 |
# File 'lib/fake_sqs/file_database.rb', line 62 def values storage.map { |key, value| deserialize(key) } end |