Class: Breaker::InMemoryRepo
- Inherits:
-
Object
- Object
- Breaker::InMemoryRepo
- Defined in:
- lib/breaker/in_memory_repo.rb
Defined Under Namespace
Classes: Fuse
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #count ⇒ Object
- #create(attributes) ⇒ Object
- #first ⇒ Object
-
#initialize ⇒ InMemoryRepo
constructor
A new instance of InMemoryRepo.
- #named(name) ⇒ Object
- #update(existing, attributes) ⇒ Object
- #upsert(attributes) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryRepo
Returns a new instance of InMemoryRepo.
22 23 24 |
# File 'lib/breaker/in_memory_repo.rb', line 22 def initialize @store = [] end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
20 21 22 |
# File 'lib/breaker/in_memory_repo.rb', line 20 def store @store end |
Instance Method Details
#count ⇒ Object
35 36 37 |
# File 'lib/breaker/in_memory_repo.rb', line 35 def count store.length end |
#create(attributes) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/breaker/in_memory_repo.rb', line 47 def create(attributes) fuse = Fuse.new attributes.each_pair do |key, value| fuse.send "#{key}=", value end store << fuse fuse end |
#first ⇒ Object
39 40 41 |
# File 'lib/breaker/in_memory_repo.rb', line 39 def first store.first end |
#named(name) ⇒ Object
43 44 45 |
# File 'lib/breaker/in_memory_repo.rb', line 43 def named(name) store.find { |fuse| fuse.name == name } end |
#update(existing, attributes) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/breaker/in_memory_repo.rb', line 59 def update(existing, attributes) existing attributes.each_pair do |key, value| existing.send "#{key}=", value end existing end |
#upsert(attributes) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/breaker/in_memory_repo.rb', line 26 def upsert(attributes) existing = named attributes.fetch(:name) if existing update existing, attributes else create attributes end end |