module AutomationObject::BluePrint::YamlAdapter
BluePrint
YAML Adapter
Public Instance Methods
build(path = '')
click to toggle source
@param path [String] path to YAML directory @return [AutomationObject::BluePrint::Composite::Top] Composite
BluePrint
Object
# File lib/automation_object/blue_print/yaml_adapter.rb, line 16 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
load_yaml_files(file_array)
click to toggle source
@param file_array [Array<String>] array of file paths to load @return [Hash] merged YAML Hash
# File lib/automation_object/blue_print/yaml_adapter.rb, line 27 def load_yaml_files(file_array) 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
yaml_file?(file_path)
click to toggle source
@param file_path [String] file path @return [Boolean] whether or not it is a YAML file
# File lib/automation_object/blue_print/yaml_adapter.rb, line 45 def yaml_file?(file_path) file_path =~ /\.ya?ml$/ ? true : false end