Module: FluShot

Defined in:
lib/flu_shot/vaccine.rb,
lib/flu_shot.rb,
lib/flu_shot/config.rb,
lib/flu_shot/sneeze.rb,
lib/flu_shot/version.rb,
lib/flu_shot/prescription.rb,
lib/flu_shot/storage/redis.rb,
lib/flu_shot/storage/memory.rb

Overview

The idea here is to do something like this in the code:

… your business layer … FluShot.inject(:user_profile_fetch)

Define a latency vaccine that you can inject into your business layer and adds a random delay between 1 and 3 seconds.

class Latency < FluShot::Vaccine

label :latency

def initialize(params)
  sleep(rand(params[:max] - params[:min]) + params[:min])
end

end

FluShot.on :user_profile_fetch do

FluShot::Vaccine.use(:latency, {min: 1000, max: 3000})

end

Defined Under Namespace

Modules: Storage Classes: Config, Error, Prescription, Sneeze, Vaccine

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.inject(name, params = {}, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flu_shot.rb', line 16

def self.inject(name, params = {}, &block)
  if !before_filter.call
    return
  end

  Prescription.for(name).each do |prescription|
    Vaccine.find(prescription[:vaccine]).new(prescription[:params].merge(params))
  end

  # @test
  _before_init
  block_given? ? block.call : nil

rescue FluShot::Sneeze => sneeze
  raise sneeze.wrapped_exception

rescue
  # @test
  _exception_muted
  block_given? ? block.call : nil
end

.inject_only_if(&block) ⇒ Object



38
39
40
# File 'lib/flu_shot.rb', line 38

def self.inject_only_if(&block)
  Thread.current[:before_filter] = block
end