Class: Huck::Generators::JsonGenerator
- Inherits:
-
Huck::Generator
- Object
- Huck::Generator
- Huck::Generators::JsonGenerator
- Defined in:
- lib/huck/generators/json.rb
Overview
JSON generator reads json files for data
Instance Attribute Summary
Attributes inherited from Huck::Generator
Instance Method Summary collapse
-
#generate ⇒ Object
Reads in a configured JSON file and returns the data.
-
#initialize ⇒ JsonGenerator
constructor
Load required modules for json generator.
-
#verify_config ⇒ Object
Ensure that all JSON config items are properly set.
Methods inherited from Huck::Generator
Constructor Details
#initialize ⇒ JsonGenerator
Load required modules for json generator
9 10 11 |
# File 'lib/huck/generators/json.rb', line 9 def initialize require 'json' end |
Instance Method Details
#generate ⇒ Object
Reads in a configured JSON file and returns the data
Returns:
A hash of facts read from the JSON file
27 28 29 30 |
# File 'lib/huck/generators/json.rb', line 27 def generate verify_config JSON.load IO.read(@config['json']['file']) end |
#verify_config ⇒ Object
Ensure that all JSON config items are properly set
14 15 16 17 18 19 20 21 |
# File 'lib/huck/generators/json.rb', line 14 def verify_config if !@config.has_key? 'json' raise RuntimeError, 'missing json config' end if !@config['json'].has_key? 'file' raise RuntimeError, 'missing json config: file' end end |