Class: HerokuMongoWatcher::Configuration
- Inherits:
-
Object
- Object
- HerokuMongoWatcher::Configuration
- Includes:
- Singleton
- Defined in:
- lib/heroku_mongo_watcher/configuration.rb
Constant Summary collapse
- @@config =
{ error_messages: ['Error', 'Exception', 'Cannot find impression', 'Timed out running'], notify: [], gmail_username: '', gmail_password: '', interval: 60, mongo_host: '', mongo_username: '', mongo_password: '', heroku_username: '', heroku_password: '', heroku_appname: '', print_errors: false, print_requests: false }
- @@valid_config_keys =
@@config.keys
Instance Method Summary collapse
- #config ⇒ Object
-
#configure(opts = {}) ⇒ Object
Configure through hash.
-
#configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/heroku_mongo_watcher/configuration.rb', line 26 def initialize f = File.join(File.('~'),'.watcher') configure_with(f) opts = Trollop:: do opt :print_errors, "show aggregate error summaries", default: false opt :print_requests, "show aggregate requests summaries", default: false opt :interval, "frequency in seconds to poll mongostat and print out results", default: 60 opt :autoscale, "autoscale dynos -- WARNING ONLY DO THIS IF YOU KNOW WHAT YOUR ARE DOING", default: false opt :min_dynos, "For autoscaling, the minimum dynos to use", default: 6 opt :max_dynos, "For autoscaling, the max dynos to use", default: 50 end @@config.merge!(opts) end |
Instance Method Details
#config ⇒ Object
43 44 45 |
# File 'lib/heroku_mongo_watcher/configuration.rb', line 43 def config @@config end |
#configure(opts = {}) ⇒ Object
Configure through hash
61 62 63 |
# File 'lib/heroku_mongo_watcher/configuration.rb', line 61 def configure(opts = {}) opts.each { |k, v| config[k.to_sym] = v if @@valid_config_keys.include? k.to_sym } end |
#configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/heroku_mongo_watcher/configuration.rb', line 48 def configure_with(path_to_yaml_file) begin y_config = YAML::load(IO.read(path_to_yaml_file)) rescue Errno::ENOENT log(:warning, "YAML configuration file couldn't be found. Using defaults."); return rescue Psych::SyntaxError log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return end configure(y_config) end |