Class: Strum::Pipeline::Storage
- Inherits:
-
Object
- Object
- Strum::Pipeline::Storage
- Defined in:
- lib/strum/pipeline/storage.rb
Overview
Class to w/r to store
Instance Attribute Summary collapse
-
#pipeline ⇒ Object
Returns the value of attribute pipeline.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(pipeline, ttl) ⇒ Storage
constructor
A new instance of Storage.
- #method_missing(method) ⇒ Object
- #respond_to_missing?(method) ⇒ Boolean
Constructor Details
#initialize(pipeline, ttl) ⇒ Storage
Returns a new instance of Storage.
16 17 18 19 |
# File 'lib/strum/pipeline/storage.rb', line 16 def initialize(pipeline, ttl) @pipeline = pipeline @ttl = ttl end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/strum/pipeline/storage.rb', line 21 def method_missing(method) that = self Class.new do define_singleton_method :[] do |key| Redis.const_get(Dry::Inflector.new.camelize(method)).new("#{that.pipeline}::#{key}", expiration: that.ttl) end end rescue StandardError super end |
Instance Attribute Details
#pipeline ⇒ Object
Returns the value of attribute pipeline.
14 15 16 |
# File 'lib/strum/pipeline/storage.rb', line 14 def pipeline @pipeline end |
#ttl ⇒ Object
Returns the value of attribute ttl.
14 15 16 |
# File 'lib/strum/pipeline/storage.rb', line 14 def ttl @ttl end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 |
# File 'lib/strum/pipeline/storage.rb', line 39 def [](key) Redis::Value.new("#{pipeline}::#{key}").value end |
#[]=(key, value) ⇒ Object
43 44 45 |
# File 'lib/strum/pipeline/storage.rb', line 43 def []=(key, value) Redis::Value.new("#{pipeline}::#{key}", expiration: ttl).value = value end |
#respond_to_missing?(method) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/strum/pipeline/storage.rb', line 33 def respond_to_missing?(method) Redis.const_get(Dry::Inflector.new.camelize(method)) rescue StandardError super end |