lib/eco/data/hashes/array_diff.rb in eco-helpers-2.5.2 vs lib/eco/data/hashes/array_diff.rb in eco-helpers-2.5.3

- old
+ new

@@ -32,18 +32,19 @@ @compared_attrs ||= [] @compared_attrs end end + include Eco::Language::AuxiliarLogger + attr_reader :source1, :source2 attr_reader :src_h1, :src_h2 - attr_reader :logger class_resolver :diff_result_class, "Eco::Data::Hash::DiffResult" - def initialize(source1, source2, logger: ::Logger.new(IO::NULL), **kargs) - @logger = logger + def initialize(source1, source2, logger: nil, **kargs) + @logger = logger if logger @options = kargs @source1 = source1 @source2 = source2 @src_h1 = by_key(source1) @src_h2 = by_key(source2) @@ -82,11 +83,12 @@ # It pairs the hashes of `source1` and `source2` # @note # - It also ensures they are in their Hash form (with string keys) # - This will merge entries of the same source that hold the same `key` attr value (latest wins) def paired_sources - keys1 = src_h1.keys; keys2 = src_h2.keys + keys1 = src_h1.keys + keys2 = src_h2.keys all_keys = keys1 | keys2 all_keys.map {|key| [src_h1[key], src_h2[key]]} end def key @@ -147,14 +149,18 @@ sample = content.to_a.first case sample when Hash, Array, ::CSV::Row Eco::CSV::Table.new(content).to_array_of_hashes else - logger.error("Input content 'Array' of '#{sample.class}' is not supported.") + log(:error) { + "Input content 'Array' of '#{sample.class}' is not supported." + } exit(1) end else - logger.error("Could not obtain any data out content: '#{content.class}'") + log(:error) { + "Could not obtain any data out content: '#{content.class}'" + } exit(1) end end end end