Class: Raterr::StoreContainer
- Inherits:
-
Object
- Object
- Raterr::StoreContainer
- Defined in:
- lib/raterr/store_container.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#store_type ⇒ Object
readonly
Returns the value of attribute store_type.
Instance Method Summary collapse
-
#initialize(store:, identifier:) ⇒ StoreContainer
constructor
A new instance of StoreContainer.
- #resolve(method, attrs = nil) ⇒ Object
- #resolvers ⇒ Object
Constructor Details
#initialize(store:, identifier:) ⇒ StoreContainer
Returns a new instance of StoreContainer.
6 7 8 9 |
# File 'lib/raterr/store_container.rb', line 6 def initialize(store:, identifier:) @store = store @identifier = identifier end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/raterr/store_container.rb', line 4 def identifier @identifier end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/raterr/store_container.rb', line 4 def store @store end |
#store_type ⇒ Object (readonly)
Returns the value of attribute store_type.
4 5 6 |
# File 'lib/raterr/store_container.rb', line 4 def store_type @store_type end |
Instance Method Details
#resolve(method, attrs = nil) ⇒ Object
11 12 13 14 |
# File 'lib/raterr/store_container.rb', line 11 def resolve(method, attrs = nil) store_type = store.class.to_s.downcase.to_sym resolvers[method][store_type].call(attrs) end |
#resolvers ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/raterr/store_container.rb', line 16 def resolvers { get: { hash: -> (attributes) { store.fetch(identifier) { { 'attempts' => 1, 'start_time' => Time.now } } }, redis: -> (attributes) { JSON.parse(store.get(identifier) || { 'attempts' => 1, 'start_time' => Time.now }.to_json) } }, set: { hash: -> (attributes) { store[identifier] = attributes }, redis: -> (attributes) { store.set(identifier, attributes.to_json) } }, delete: { hash: -> (identifier) { store.delete(identifier) }, redis: -> (identifier) { store.del(identifier) } } } end |