Class: Strum::Pipeline::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/strum/pipeline/storage.rb

Overview

Class to w/r to store

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pipelineObject

Returns the value of attribute pipeline.



14
15
16
# File 'lib/strum/pipeline/storage.rb', line 14

def pipeline
  @pipeline
end

#ttlObject

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

Returns:

  • (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