Class: Orchestra::Recording::Playback::Factory

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFactory

Returns a new instance of Factory.



22
23
24
25
# File 'lib/orchestra/recording/playback.rb', line 22

def initialize
  @klass = Class.new Playback
  @mocks = Hash.new do |hsh, meth| hsh[meth] = {} end
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



20
21
22
# File 'lib/orchestra/recording/playback.rb', line 20

def klass
  @klass
end

Instance Method Details

#<<(record) ⇒ Object



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

def << record
  method = record[:method].to_sym
  unless klass.instance_methods.include? method
    klass.send :define_method, method do |*args| mocks[method][args] end
  end
  mocks[method][record[:input]] = record[:output]
end

#build(service_recording) ⇒ Object



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

def build service_recording
  record = method :<<
  service_recording.each &record
  klass.new mocks
end

#singletonObject



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

def singleton
  singleton = class << instance ; self end
end