Updated

lib/automation_object/blue_print / yaml_adapter.rb

A
50 lines of codes
3 methods
5.7 complexity/method
13 loc/method
17 complexity
0 duplications
# frozen_string_literal: true require 'yaml' require_relative '../helpers/file' require_relative 'hash_adapter' module AutomationObject module BluePrint # BluePrint YAML Adapter module YamlAdapter module_function # @param path [String] path to YAML directory # @return [AutomationObject::BluePrint::Composite::Top] Composite BluePrint Object def build(path = '') path = File.expand_path(path) file_array = File.collect_files(path) merged_yaml_hash = load_yaml_files(file_array) AutomationObject::BluePrint::HashAdapter.build(merged_yaml_hash) end # @param file_array [Array<String>] array of file paths to load # @return [Hash] merged YAML Hash def load_yaml_files(file_array)
  1. AutomationObject::BluePrint::YamlAdapter#load_yaml_files has approx 7 statements
merged_yaml_hash = {} file_array.each do |file_path| next unless yaml_file?(file_path) file_hash = YAML.load_file(file_path) raise "Expecting file #{file_path} to be a hash when loaded" unless file_hash.is_a?(Hash) merged_yaml_hash = merged_yaml_hash.deep_merge(file_hash) end merged_yaml_hash end # @param file_path [String] file path # @return [Boolean] whether or not it is a YAML file def yaml_file?(file_path) file_path =~ /\.ya?ml$/ ? true : false
  1. AutomationObject::BluePrint::YamlAdapter#yaml_file? is controlled by argument 'file_path'
end end end end