Method: OFlow::Actors::Recorder#initialize

Defined in:
lib/oflow/actors/recorder.rb

#initialize(task, options) ⇒ Recorder

Initializes the recorder with options of:

Parameters:

  • options (Hash)

    with keys of

    • :dir [String] directory to store the persisted records

    • :results_path [String] path to where the results should be placed in

      the request (default: nil or ship only results)
      


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oflow/actors/recorder.rb', line 19

def initialize(task, options)
  super
  @cache = {}
  @dir = options[:dir]
  if @dir.nil?
    @dir = File.join('db', task.full_name.gsub(':', '/'))
  end
  @dir = File.expand_path(@dir.strip)
  @results_path = options[:results_path]
  @results_path.strip! unless @results_path.nil?

  if Dir.exist?(@dir)
    Dir.glob(File.join(@dir, '*.json')).each do |path|
      load(path)
    end
  else
    `mkdir -p #{@dir}`
  end
end