Module: AutomationObject::BluePrint::YamlAdapter
- Defined in:
- lib/automation_object/blue_print/yaml_adapter.rb
Overview
BluePrint YAML Adapter
Class Method Summary collapse
-
.build(path = '') ⇒ AutomationObject::BluePrint::Composite::Top
Composite BluePrint Object.
-
.load_yaml_files(file_array) ⇒ Hash
Merged YAML Hash.
-
.yaml_file?(file_path) ⇒ Boolean
Whether or not it is a YAML file.
Class Method Details
.build(path = '') ⇒ AutomationObject::BluePrint::Composite::Top
Returns Composite BluePrint Object
16 17 18 19 20 21 22 23 |
# File 'lib/automation_object/blue_print/yaml_adapter.rb', line 16 def build(path = '') path = File.(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) ⇒ Hash
Returns merged YAML Hash
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Boolean
Returns whether or not it is a YAML file
45 46 47 |
# File 'lib/automation_object/blue_print/yaml_adapter.rb', line 45 def yaml_file?(file_path) file_path =~ /\.ya?ml$/ ? true : false end |