lib/cascade/columns_matching.rb in cascade-rb-0.2.3 vs lib/cascade/columns_matching.rb in cascade-rb-0.3.0

- old
+ new

@@ -1,42 +1,43 @@ -require "yaml" +# frozen_string_literal: true + +require 'yaml' require 'forwardable' -require "cascade/exceptions" -require "cascade/helpers/configuration" +require 'cascade/exceptions' module Cascade class ColumnsMatching extend Forwardable - extend Configuration - define_setting :mapping_file + ROOT_KEY = 'mapping' def_delegator :supported_keys, :index def initialize(options = {}) - @filepath = options[:filepath] - @content = options.fetch(:content) { parse_content_file } + @content = options.fetch(:content) do + parse_content_file(options.fetch(:filepath)) + end end # Defines set of possible keys that can be used for iterating through - # parsed line + # the parsed line # - # @return [Array] of supported keys + # @return [Array] of the supported keys def supported_keys @supported_keys ||= @content.keys end # Presenter for passed key # - # @return [Symbol] with curresponding value + # @return [Symbol] with the corresponding value def column_type(key) @content[key].to_sym end private - def parse_content_file - content = YAML.load_file(@filepath || self.class.mapping_file) - (content && content["mapping"]) || raise(Cascade::WrongMappingFormat.new) + def parse_content_file(filepath) + content = YAML.load_file(filepath) + (content && content[ROOT_KEY]) || raise(Cascade::WrongMappingFormat) end end end