Class: Huck::Generators::YamlGenerator

Inherits:
Huck::Generator show all
Defined in:
lib/huck/generators/yaml.rb

Overview

YAML generator reads yaml files for data

Instance Attribute Summary

Attributes inherited from Huck::Generator

#config

Instance Method Summary collapse

Methods inherited from Huck::Generator

#dump, factory

Constructor Details

#initializeYamlGenerator

Load required modules for yaml generator



9
10
11
# File 'lib/huck/generators/yaml.rb', line 9

def initialize
  require 'yaml'
end

Instance Method Details

#generateObject

Reads in a configured YAML file and returns the data

Returns:

A hash of facts read from the YAML file



27
28
29
30
# File 'lib/huck/generators/yaml.rb', line 27

def generate
  verify_config
  YAML.load_file @config['yaml']['file']
end

#verify_configObject

Ensure that all YAML config items are properly set



14
15
16
17
18
19
20
21
# File 'lib/huck/generators/yaml.rb', line 14

def verify_config
  if !@config.has_key? 'yaml'
    raise RuntimeError, 'missing yaml config'
  end
  if !@config['yaml'].has_key? 'file'
    raise RuntimeError, 'missing yaml config: file'
  end
end