Class: FacterStatistax::Common::OutputWriter

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/common/output_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOutputWriter

Returns a new instance of OutputWriter.



11
12
13
14
15
# File 'lib/common/output_writer.rb', line 11

def initialize
  @output = []
  @test_run = {}
  @facts = []
end

Instance Attribute Details

#factsObject (readonly)

Returns the value of attribute facts.



10
11
12
# File 'lib/common/output_writer.rb', line 10

def facts
  @facts
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/common/output_writer.rb', line 10

def output
  @output
end

#test_runObject (readonly)

Returns the value of attribute test_run.



10
11
12
# File 'lib/common/output_writer.rb', line 10

def test_run
  @test_run
end

Instance Method Details

#writeObject



17
18
19
20
21
22
23
# File 'lib/common/output_writer.rb', line 17

def write
  test_run = @test_run.merge(facts: facts)
  output << test_run
  ::File.open(File.join(LOG_DIR, 'output.json'), 'w') do |file|
    file.write(output.to_json)
  end
end

#write_run(fact_name, time) ⇒ Object



29
30
31
32
33
# File 'lib/common/output_writer.rb', line 29

def write_run(fact_name, time)
  fact_name = 'all' if fact_name.empty?
  fact = { 'name' => fact_name, 'average' => time.real }
  facts << fact
end

#write_test_suite(facter_version, test_run_name) ⇒ Object



25
26
27
# File 'lib/common/output_writer.rb', line 25

def write_test_suite(facter_version, test_run_name)
  @test_run = @test_run.merge(test_run_name: test_run_name, facter_gem?: facter_version)
end