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.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
-
.read_from_files(kind, *file_names, configuration: Configuration.new) ⇒ Hash<Symbol, FactoryTrace::Structures::Collection>
Read the data from files and merge it.
Instance Method Summary collapse
-
#initialize(kind, 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(kind, io, configuration: Configuration.new) ⇒ TraceReader
Returns a new instance of TraceReader.
27 28 29 30 31 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 27 def initialize(kind, io, configuration: Configuration.new) @kind = kind @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 |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
6 7 8 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 6 def kind @kind end |
Class Method Details
.read_from_files(kind, *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(kind, *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(kind, file, configuration: configuration).read [:defined, :used].each do |key| result[key].merge!(data[key]) unless data.empty? end end end result end |
Instance Method Details
#read ⇒ Hash<Symbol, FactoryTrace::Structures::Collection>
Read the data from file
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/factory_trace/readers/trace_reader.rb', line 36 def read hash = JSON.parse(io.read) defined = hash["defined"][kind.to_s] used = hash["used"][kind.to_s] return {} if defined.nil? || used.nil? { defined: parse_collection(defined), used: parse_collection(used) } end |