Class: Skewer::SkewerConfig
Overview
responsible for all configuration, once I move all the options in
Instance Attribute Summary collapse
-
#aws_service ⇒ Object
Returns the value of attribute aws_service.
-
#aws_username ⇒ Object
Returns the value of attribute aws_username.
-
#flavor_id ⇒ Object
Returns the value of attribute flavor_id.
-
#puppet_repo ⇒ Object
Returns the value of attribute puppet_repo.
-
#region ⇒ Object
Returns the value of attribute region.
Class Method Summary collapse
Instance Method Summary collapse
- #get(attribute) ⇒ Object
-
#initialize ⇒ SkewerConfig
constructor
A new instance of SkewerConfig.
- #parse(config) ⇒ Object
- #read_config_file(config_file) ⇒ Object
- #read_config_files ⇒ Object
- #reset ⇒ Object
- #set(attribute, value) ⇒ Object
- #slurp_options(options) ⇒ Object
Constructor Details
#initialize ⇒ SkewerConfig
Returns a new instance of SkewerConfig.
9 10 11 12 |
# File 'lib/config.rb', line 9 def initialize reset read_config_files end |
Instance Attribute Details
#aws_service ⇒ Object
Returns the value of attribute aws_service.
7 8 9 |
# File 'lib/config.rb', line 7 def aws_service @aws_service end |
#aws_username ⇒ Object
Returns the value of attribute aws_username.
7 8 9 |
# File 'lib/config.rb', line 7 def aws_username @aws_username end |
#flavor_id ⇒ Object
Returns the value of attribute flavor_id.
7 8 9 |
# File 'lib/config.rb', line 7 def flavor_id @flavor_id end |
#puppet_repo ⇒ Object
Returns the value of attribute puppet_repo.
7 8 9 |
# File 'lib/config.rb', line 7 def puppet_repo @puppet_repo end |
#region ⇒ Object
Returns the value of attribute region.
7 8 9 |
# File 'lib/config.rb', line 7 def region @region end |
Class Method Details
.get(key) ⇒ Object
57 58 59 |
# File 'lib/config.rb', line 57 def self.get(key) self.instance.get(key) end |
.set(key, value) ⇒ Object
45 46 47 48 |
# File 'lib/config.rb', line 45 def self.set(key,value) instance = self.instance instance.set(key,value) end |
Instance Method Details
#get(attribute) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/config.rb', line 50 def get(attribute) if attribute.class == Symbol attribute = attribute.to_s end self.instance_variable_get "@" + attribute end |
#parse(config) ⇒ Object
35 36 37 38 39 |
# File 'lib/config.rb', line 35 def parse(config) require 'json' configz = JSON.parse(config) configz.each { |key,value| set(key,value) } end |
#read_config_file(config_file) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/config.rb', line 21 def read_config_file(config_file) if File.exists?(config_file) Skewer.logger.debug "reading #{config_file}" config = File.read(config_file) parse(config) Skewer.logger.debug self.inspect end end |
#read_config_files ⇒ Object
30 31 32 33 |
# File 'lib/config.rb', line 30 def read_config_files read_config_file(File.join(ENV['HOME'], '.skewer.json')) read_config_file('.skewer.json') end |
#reset ⇒ Object
14 15 16 17 18 19 |
# File 'lib/config.rb', line 14 def reset @puppet_repo = '../infrastructure' @region = 'us-east-1' @flavor_id = 'm1.large' @aws_username = 'ubuntu' end |
#set(attribute, value) ⇒ Object
41 42 43 |
# File 'lib/config.rb', line 41 def set(attribute, value) self.instance_variable_set "@#{attribute}", value end |
#slurp_options(options) ⇒ Object
61 62 63 64 65 |
# File 'lib/config.rb', line 61 def () .each_pair do |key, value| self.set(key, value) end end |