Class: Bosh::Clouds::Dummy::InputsRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/dummy.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_dir, logger) ⇒ InputsRecorder

Returns a new instance of InputsRecorder.



581
582
583
584
# File 'lib/cloud/dummy.rb', line 581

def initialize(base_dir, logger)
  @cpi_inputs_dir = File.join(base_dir, 'cpi_inputs')
  @logger = logger
end

Instance Method Details

#ordered_file_pathObject



610
611
612
# File 'lib/cloud/dummy.rb', line 610

def ordered_file_path
  File.join(@cpi_inputs_dir, 'all_requests')
end

#read(method_name) ⇒ Object



593
594
595
596
597
598
# File 'lib/cloud/dummy.rb', line 593

def read(method_name)
  @logger.info("Reading input for #{method_name}")
  read_all.select do |invocation|
    invocation.method_name == method_name
  end
end

#read_allObject



600
601
602
603
604
605
606
607
608
# File 'lib/cloud/dummy.rb', line 600

def read_all
  @logger.info("Reading all inputs: #{File.read(ordered_file_path)}")
  result = []
  File.read(ordered_file_path).split("\n").each do |request|
    data = JSON.parse(request)
    result << CpiInvocation.new(data['method_name'], data['inputs'])
  end
  result
end

#record(method, args) ⇒ Object



586
587
588
589
590
591
# File 'lib/cloud/dummy.rb', line 586

def record(method, args)
  FileUtils.mkdir_p(@cpi_inputs_dir)
  data = {method_name: method, inputs: args}
  @logger.info("Saving input for #{method} #{data} #{ordered_file_path}")
  File.open(ordered_file_path, 'a') { |f| f.puts(JSON.dump(data)) }
end