Class: Nadir::Config
- Inherits:
-
Object
- Object
- Nadir::Config
- Defined in:
- lib/nadir/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#enabled_for ⇒ Object
Returns the value of attribute enabled_for.
-
#env ⇒ Object
Returns the value of attribute env.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_for(app) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 |
# File 'lib/nadir/config.rb', line 12 def initialize @env = ENV['NADIR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] @api_key = ENV['NADIR_API_KEY'] @api_url = 'https://nadir.dev/api'.freeze @enabled_for = %w(production staging) @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/nadir/config.rb', line 5 def api_key @api_key end |
#api_url ⇒ Object
Returns the value of attribute api_url.
5 6 7 |
# File 'lib/nadir/config.rb', line 5 def api_url @api_url end |
#enabled_for ⇒ Object
Returns the value of attribute enabled_for.
5 6 7 |
# File 'lib/nadir/config.rb', line 5 def enabled_for @enabled_for end |
#env ⇒ Object
Returns the value of attribute env.
5 6 7 |
# File 'lib/nadir/config.rb', line 5 def env @env end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/nadir/config.rb', line 5 def logger @logger end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/nadir/config.rb', line 5 def root @root end |
Instance Method Details
#load_for(app) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nadir/config.rb', line 37 def load_for(app) @env ||= Rails.env @root = app.root config_file = @root.join 'config/nadir.yml' file_config = YAML.safe_load File.read config_file @api_key = file_config['api_key'] if file_config['api_key'] @api_url = file_config['api_url'] if file_config['api_url'] @enabled_for = file_config['enabled_for'] if file_config['enabled_for'] end |
#validate ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nadir/config.rb', line 21 def validate unless @api_key logger.warn '[Nadir] API-KEY not set, skipping notifications.' return false end unless @enabled_for.include? @env.to_s logger.warn "[Nadir] Reporting disabled for environment '#{@env}', skipping notification." return false end true end |