Class: Orchestra::Recording

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestra/recording.rb,
lib/orchestra/recording/node.rb,
lib/orchestra/recording/playback.rb

Defined Under Namespace

Classes: Node, Playback

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(services) ⇒ Recording

Returns a new instance of Recording.



11
12
13
# File 'lib/orchestra/recording.rb', line 11

def initialize services
  @services = services
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



8
9
10
# File 'lib/orchestra/recording.rb', line 8

def input
  @input
end

#outputObject

Returns the value of attribute output.



8
9
10
# File 'lib/orchestra/recording.rb', line 8

def output
  @output
end

#servicesObject (readonly)

Returns the value of attribute services.



9
10
11
# File 'lib/orchestra/recording.rb', line 9

def services
  @services
end

Class Method Details

.freshObject



3
4
5
6
# File 'lib/orchestra/recording.rb', line 3

def self.fresh
  services = Hash.new do |hsh, service_name| hsh[service_name] = [] end
  new services
end

Instance Method Details

#[](attr) ⇒ Object



28
29
30
# File 'lib/orchestra/recording.rb', line 28

def [] attr
  to_h[attr]
end

#replay(operation, override_input = {}) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/orchestra/recording.rb', line 44

def replay operation, override_input = {}
  replayed_services = {}
  services.each do |svc, service_recording|
    replayed_services[svc] = Playback.build service_recording
  end
  conductor = Conductor.new replayed_services
  conductor.execute operation, input.merge(override_input)
end

#to_hObject



32
33
34
35
36
37
38
# File 'lib/orchestra/recording.rb', line 32

def to_h
  {
    :input              => input,
    :output             => output,
    :service_recordings => services,
  }
end

#to_json(generator) ⇒ Object



40
41
42
# File 'lib/orchestra/recording.rb', line 40

def to_json generator
  generator.generate to_h
end

#update(event_name, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/orchestra/recording.rb', line 15

def update event_name, *args
  case event_name
  when :service_accessed then
    service_name, recording = args
    @services[service_name] << recording
  when :operation_entered then
    _, @input = args
  when :operation_exited then
    _, @output = args
  else
  end
end