Class: Spout::Helpers::ConfigReader
- Inherits:
-
Object
- Object
- Spout::Helpers::ConfigReader
- Defined in:
- lib/spout/helpers/config_reader.rb
Overview
Loads the .spout.yml configuration file.
Instance Attribute Summary collapse
-
#charts ⇒ Object
readonly
Returns the value of attribute charts.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#visit ⇒ Object
readonly
Returns the value of attribute visit.
-
#webservers ⇒ Object
readonly
Returns the value of attribute webservers.
Instance Method Summary collapse
-
#initialize ⇒ ConfigReader
constructor
A new instance of ConfigReader.
- #parse_yaml_file ⇒ Object
Constructor Details
#initialize ⇒ ConfigReader
Returns a new instance of ConfigReader.
11 12 13 14 15 16 17 |
# File 'lib/spout/helpers/config_reader.rb', line 11 def initialize @slug = "" @visit = "" @charts = [] @webservers = [] parse_yaml_file end |
Instance Attribute Details
#charts ⇒ Object (readonly)
Returns the value of attribute charts.
9 10 11 |
# File 'lib/spout/helpers/config_reader.rb', line 9 def charts @charts end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
9 10 11 |
# File 'lib/spout/helpers/config_reader.rb', line 9 def slug @slug end |
#visit ⇒ Object (readonly)
Returns the value of attribute visit.
9 10 11 |
# File 'lib/spout/helpers/config_reader.rb', line 9 def visit @visit end |
#webservers ⇒ Object (readonly)
Returns the value of attribute webservers.
9 10 11 |
# File 'lib/spout/helpers/config_reader.rb', line 9 def webservers @webservers end |
Instance Method Details
#parse_yaml_file ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/spout/helpers/config_reader.rb', line 19 def parse_yaml_file spout_config = YAML.load_file(".spout.yml") if spout_config.is_a?(Hash) @slug = spout_config["slug"].to_s.strip @visit = spout_config["visit"].to_s.strip @charts = \ if spout_config["charts"].is_a?(Array) spout_config["charts"].select { |c| c.is_a?(Hash) } else [] end @webservers = \ if spout_config["webservers"].is_a?(Array) spout_config["webservers"].select { |c| c.is_a?(Hash) } else [] end else puts "The YAML file needs to be in the following format:" puts "---\nvisit: visit_variable_name\ncharts:\n- chart: age_variable_name\n title: Age\n- chart: gender_variable_name\n title: Gender\n- chart: race_variable_name\n title: Race\n" end end |