Class: Pingity::Config
- Inherits:
-
Object
- Object
- Pingity::Config
- Defined in:
- lib/pingity/config.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :config_path => "~/.pingityrc", :api => 'api.pingity.com', :api_key => nil, :verbose => false }.freeze
- ENV_VARIABLE_PREFIX =
/^PINGITY_/.freeze
Instance Method Summary collapse
-
#initialize(options = nil) ⇒ Config
constructor
A new instance of Config.
- #transport ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = nil) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pingity/config.rb', line 13 def initialize( = nil) @options = DEFAULT_OPTIONS.dup if () @options.merge!() end ENV.each do |variable, value| next unless (variable.match(ENV_VARIABLE_PREFIX)) key_name = variable.sub(ENV_VARIABLE_PREFIX, '').downcase next if (key_name.empty?) @options[key_name.to_sym] = value end config_path = File.(@options[:config_path]) if (config_path and !config_path.empty? and File.exist?(config_path)) config = YAML.load(File.read(config_path)) @options.merge!(Hash[ config.collect do |k, v| [ k.to_sym, v ] end ]) end end |
Instance Method Details
#transport ⇒ Object
47 48 49 |
# File 'lib/pingity/config.rb', line 47 def transport :net_http end |
#valid? ⇒ Boolean
43 44 45 |
# File 'lib/pingity/config.rb', line 43 def valid? !!(@api_key and !@api_key.empty?) end |