Class: RGovData::Config
- Inherits:
-
Object
- Object
- RGovData::Config
- Includes:
- Singleton
- Defined in:
- lib/rgovdata/config/config.rb
Defined Under Namespace
Classes: ConfigError, ConfigurationFileInitialized, ConfigurationFileNotFound
Constant Summary collapse
- BASE_NAME =
'rgovdata.conf'
Instance Attribute Summary collapse
-
#credentialsets ⇒ Object
Returns the value of attribute credentialsets.
-
#default_realm ⇒ Object
Returns the value of attribute default_realm.
Class Method Summary collapse
- .default_config_file(override = nil) ⇒ Object
- .default_loader_options ⇒ Object
- .require_config_file ⇒ Object
- .reset_configfile(configfilepath) ⇒ Object
- .template ⇒ Object
- .template_path ⇒ Object
Instance Method Summary collapse
-
#clear ⇒ Object
Clears the current configuration.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_config(configfilepath, options = {}) ⇒ Object
-
#load_default_config ⇒ Object
Reloads configuraiton from default config provider - rails config file (if used in Rails) - current directory - environment settings.
-
#show_status ⇒ Object
Prints current status.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
17 18 19 |
# File 'lib/rgovdata/config/config.rb', line 17 def initialize load_default_config end |
Instance Attribute Details
#credentialsets ⇒ Object
Returns the value of attribute credentialsets.
15 16 17 |
# File 'lib/rgovdata/config/config.rb', line 15 def credentialsets @credentialsets end |
#default_realm ⇒ Object
Returns the value of attribute default_realm.
15 16 17 |
# File 'lib/rgovdata/config/config.rb', line 15 def default_realm @default_realm end |
Class Method Details
.default_config_file(override = nil) ⇒ Object
112 113 114 |
# File 'lib/rgovdata/config/config.rb', line 112 def default_config_file(override = nil) File.(override || BASE_NAME) end |
.default_loader_options ⇒ Object
124 125 126 |
# File 'lib/rgovdata/config/config.rb', line 124 def @@default_loader_options ||= {:generate_default => false,:required => false} end |
.require_config_file ⇒ Object
128 129 130 |
# File 'lib/rgovdata/config/config.rb', line 128 def require_config_file @@default_loader_options = {:generate_default => true,:required => true} end |
.reset_configfile(configfilepath) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/rgovdata/config/config.rb', line 104 def reset_configfile(configfilepath) file = File.new(configfilepath,'w') template.each_line do | line| file.puts line end file.close end |
Instance Method Details
#clear ⇒ Object
Clears the current configuration
73 74 75 76 |
# File 'lib/rgovdata/config/config.rb', line 73 def clear @credentialsets = {} @default_realm = nil end |
#load_config(configfilepath, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rgovdata/config/config.rb', line 45 def load_config(configfilepath, = {}) .reverse_merge!(:generate_default => true,:required => true) unless File.exists?(configfilepath) self.class.reset_configfile(configfilepath) if [:generate_default] if File.exists?(configfilepath) raise ConfigurationFileInitialized.new("\n No configuration file found. A new file has been initialized at: #{configfilepath} Please review the configuration and retry..\n\n\n") elsif [:required] raise ConfigurationFileNotFound.new("cannot load config file #{configfilepath}") else return end end update_settings(OpenStruct.new(YAML::load(File.read(configfilepath)))) end |
#load_default_config ⇒ Object
Reloads configuraiton from default config provider
-
rails config file (if used in Rails)
-
current directory
-
environment settings
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rgovdata/config/config.rb', line 25 def load_default_config clear # load default config if rails_root # if rails env, load from Rails.root.join('config',BASE_NAME) load_config(rails_root.join('config',BASE_NAME),self.class.) elsif # else load from pwd load_config(self.class.default_config_file,self.class.) else # else just refresh_from_env refresh_from_env end end |
#show_status ⇒ Object
Prints current status
79 80 81 82 83 84 85 86 |
# File 'lib/rgovdata/config/config.rb', line 79 def show_status if credentialsets puts "credential sets available: #{credentialsets.keys.join(',')}" puts credentialsets.inspect else puts "credential sets available: none" end end |