Class: NeetoMonitorRuby::Configuration
- Inherits:
-
Object
- Object
- NeetoMonitorRuby::Configuration
- Defined in:
- lib/neeto_monitor_ruby/configuration.rb
Constant Summary collapse
- BASE_URL =
"https://neetomonitor.com".freeze
- DEFAULT_PING_TIMEOUT =
8
- DEFAULT_CONFIG_PATH =
"config/neetomonitor.yml"
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#key_prefix ⇒ Object
Returns the value of attribute key_prefix.
-
#key_prefix_enabled ⇒ Object
Returns the value of attribute key_prefix_enabled.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#monitors ⇒ Object
Returns the value of attribute monitors.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#ping_timeout ⇒ Object
Returns the value of attribute ping_timeout.
-
#sidekiq_enabled ⇒ Object
Returns the value of attribute sidekiq_enabled.
Class Method Summary collapse
- .configure!(options = {}, reset = false) ⇒ Object
- .load_config(file_path) ⇒ Object
- .load_config?(config_path) ⇒ Boolean
- .reset! ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 64 def initialize( = {}) @options = @base_url = fetch_or_set_value(:base_url, BASE_URL) @api_key = fetch_or_set_value(:api_key) @environment = fetch_or_set_value(:environment) @ping_timeout = fetch_or_set_value(:ping_timeout, DEFAULT_PING_TIMEOUT) @logger = Logger.new($stdout) @sidekiq_enabled = fetch_or_set_value(:sidekiq_enabled, true) @config_path = fetch_or_set_value(:config_path) @monitors = [:monitors] @key_prefix_enabled = fetch_or_set_value(:key_prefix_enabled, true) @key_prefix = fetch_or_set_value(:key_prefix, app_key_prefix) end |
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 14 def config @config end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def base_url @base_url end |
#config_path ⇒ Object
Returns the value of attribute config_path.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def config_path @config_path end |
#environment ⇒ Object
Returns the value of attribute environment.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def environment @environment end |
#key_prefix ⇒ Object
Returns the value of attribute key_prefix.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def key_prefix @key_prefix end |
#key_prefix_enabled ⇒ Object
Returns the value of attribute key_prefix_enabled.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def key_prefix_enabled @key_prefix_enabled end |
#logger ⇒ Object
Returns the value of attribute logger.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def logger @logger end |
#monitors ⇒ Object
Returns the value of attribute monitors.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def monitors @monitors end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
62 63 64 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 62 def @options end |
#ping_timeout ⇒ Object
Returns the value of attribute ping_timeout.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def ping_timeout @ping_timeout end |
#sidekiq_enabled ⇒ Object
Returns the value of attribute sidekiq_enabled.
59 60 61 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 59 def sidekiq_enabled @sidekiq_enabled end |
Class Method Details
.configure!(options = {}, reset = false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 16 def configure!( = {}, reset = false) return config if !config.nil? && !reset reset! if reset = .dup config_path = if [:config_path] [:config_path] else file_path = ENV.fetch("NEETO_MONITOR_CONFIG_PATH", DEFAULT_CONFIG_PATH) defined?(Rails) && Rails.respond_to?(:root) ? Rails.root.join(file_path) : file_path end = load_config(config_path).merge() if config_path && load_config?(config_path) self.config = Configuration.new() config end |
.load_config(file_path) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 47 def load_config(file_path) config = YAML.load(ERB.new(File.read(file_path)).result(binding)) JSON.parse(JSON[config], symbolize_names: true) rescue Errno::ENOENT raise ConfigurationError.new("#{file_path} not found") rescue Psych::SyntaxError => e raise ConfigurationError.new("#{file_path} is malformed: #{e.}") end |
.load_config?(config_path) ⇒ Boolean
43 44 45 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 43 def load_config?(config_path) File.exist?(config_path) end |
.reset! ⇒ Object
37 38 39 40 41 |
# File 'lib/neeto_monitor_ruby/configuration.rb', line 37 def reset! self.config = Configuration.new config end |