Module: Hiatus::Mixin::ClassMethods

Defined in:
lib/hiatus/mixin.rb

Defined Under Namespace

Classes: NoCircuitFactoryProvided

Instance Method Summary collapse

Instance Method Details

#_circuit_factory_Object



25
# File 'lib/hiatus/mixin.rb', line 25

def _circuit_factory_; @circuit_factory; end

#circuit_break(method) ⇒ Object Also known as: circuit_protected



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hiatus/mixin.rb', line 27

def circuit_break(method)
  raise NoCircuitFactoryProvided unless @circuit_factory

  unbounded_method_to_decorate = instance_method method

  define_method method do |*args, &block|
    @_circuit_breaker_ ||= self.class._circuit_factory_[]

    @_circuit_breaker_.run do
      unbounded_method_to_decorate.bind(self)[*args, &block]
    end
  end

  define_method :circuit_breaker do
    @_circuit_breaker_
  end

  private :circuit_breaker
end

#circuit_factory(callable) ⇒ Object



21
22
23
# File 'lib/hiatus/mixin.rb', line 21

def circuit_factory(callable)
  @circuit_factory = callable || Hiatus::Mixin.default_circuit_factory
end