Class: Chaos::Injection

Inherits:
Object
  • Object
show all
Defined in:
lib/chaos/injection.rb

Constant Summary collapse

ATTRIBUTES =
%i(target method_name instability_type instability_arguments probability execute_if).freeze

Instance Method Summary collapse

Constructor Details

#initialize(instability_factory: Chaos::InstabilityFactory.new) ⇒ Injection

Returns a new instance of Injection.



9
10
11
# File 'lib/chaos/injection.rb', line 9

def initialize(instability_factory: Chaos::InstabilityFactory.new)
  @instability_factory = instability_factory
end

Instance Method Details

#execute_ifObject



23
24
25
# File 'lib/chaos/injection.rb', line 23

def execute_if
  @execute_if || ->(_arg) { true }
end

#execute_if=(val) ⇒ Object



27
28
29
30
# File 'lib/chaos/injection.rb', line 27

def execute_if=(val)
  raise "is not a lambda-like object" if !val.respond_to?(:call)
  @execute_if = val
end

#instabilityObject



19
20
21
# File 'lib/chaos/injection.rb', line 19

def instability
  instability_factory.build(instability_type)
end

#validate!Object



13
14
15
16
17
# File 'lib/chaos/injection.rb', line 13

def validate!
  ATTRIBUTES.each do |attribute|
    present?(public_send(attribute)) or raise ":#{attribute} is not set!"
  end
end