Module: Strum::Pipeline

Extended by:
Dry::Configurable
Defined in:
lib/strum/pipeline.rb,
lib/strum/pipeline/storage.rb,
lib/strum/pipeline/version.rb

Overview

rubocop:disable Style/Documentation

Defined Under Namespace

Modules: ClassMethods Classes: Error, Storage

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Classes = []



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/strum/pipeline.rb', line 34

def self.included(base)
  base.class_eval do
    include Strum::Esb::Handler

    attr_accessor :handler_bind

    def after_headers_hook(bind)
      @handler_bind = bind
      setup_pipeline
    end

    def setup_pipeline
      Thread.current[:pipeline] ||= self.class.pipeline_name
      Thread.current[:pipeline_id] = SecureRandom.hex(10) if init_step?
    end

    def init_step?
      if eval("action", handler_bind)
        self.class.inits.include?(["action", eval("action", handler_bind), eval("resource", handler_bind)].join("-"))
      elsif eval("event", handler_bind)
        self.class.inits.include?(["event", eval("resource", handler_bind), eval("event", handler_bind), eval("state", handler_bind)].join("-"))
      elsif eval("info", handler_bind)
        self.class.inits.include?(["info", eval("info", handler_bind)].join("-"))
      elsif eval("notice", handler_bind)
        self.class.inits.include?(["notice", eval("resource", handler_bind), eval("notice", handler_bind)].join("-"))
      end
    end
  end

  base.extend ClassMethods
end

Instance Method Details

#pipeline_keyObject



111
112
113
# File 'lib/strum/pipeline.rb', line 111

def pipeline_key
  [Thread.current[:pipeline], Thread.current[:pipeline_id]].join("-")
end

#storageObject



107
108
109
# File 'lib/strum/pipeline.rb', line 107

def storage
  Thread.current[:storage] ||= Strum::Pipeline::Storage.new(pipeline_key, Strum::Pipeline.config.ttl)
end