Class: FactoryTrace::Readers::TraceReader
- Inherits:
-
Object
- Object
- FactoryTrace::Readers::TraceReader
- Defined in:
- lib/factory_trace/readers/trace_reader.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Class Method Summary collapse
-
.read_from_files(*file_names, configuration: Configuration.new) ⇒ Hash<Symbol, FactoryTrace::Structures::Collection>
Read the data from files and merge it.
Instance Method Summary collapse
-
#initialize(io, configuration: Configuration.new) ⇒ TraceReader
constructor
A new instance of TraceReader.
-
#read ⇒ Hash<Symbol, FactoryTrace::Structures::Collection>
Read the data from file.
Constructor Details
#initialize(io, configuration: Configuration.new) ⇒ TraceReader
Returns a new instance of TraceReader.
27 28 29 30 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 27 def initialize(io, configuration: Configuration.new) @io = io @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 6 def configuration @configuration end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
6 7 8 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 6 def io @io end |
Class Method Details
.read_from_files(*file_names, configuration: Configuration.new) ⇒ Hash<Symbol, FactoryTrace::Structures::Collection>
Read the data from files and merge it
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 11 def self.read_from_files(*file_names, configuration: Configuration.new) result = {defined: FactoryTrace::Structures::Collection.new, used: FactoryTrace::Structures::Collection.new} file_names.each do |file_name| File.open(file_name, "r") do |file| data = new(file, configuration: configuration).read [:defined, :used].each do |key| result[key].merge!(data[key]) end end end result end |
Instance Method Details
#read ⇒ Hash<Symbol, FactoryTrace::Structures::Collection>
Read the data from file
35 36 37 38 39 40 41 42 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 35 def read hash = JSON.parse(io.read) { defined: parse_collection(hash["defined"]), used: parse_collection(hash["used"]) } end |