Sha256: 27023ddfbfcbc24d65b2e7955cbf1fb12cbc62ffc825bc524998d644a64a748a

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

require 'yaml'

module Nadir
  class Config
    attr_accessor :api_key,
                  :api_url,
                  :env,
                  :logger,
                  :root,
                  :enabled_for

    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

    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

    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
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nadir-1.2.1 lib/nadir/config.rb
nadir-1.2.0 lib/nadir/config.rb
nadir-1.1.10 lib/nadir/config.rb
nadir-1.1.9 lib/nadir/config.rb
nadir-1.1.8 lib/nadir/config.rb
nadir-1.1.7 lib/nadir/config.rb
nadir-1.1.6 lib/nadir/config.rb
nadir-1.1.5 lib/nadir/config.rb
nadir-1.1.4 lib/nadir/config.rb
nadir-1.1.3 lib/nadir/config.rb
nadir-1.1.2 lib/nadir/config.rb
nadir-1.1.1 lib/nadir/config.rb
nadir-1.1.0 lib/nadir/config.rb
nadir-1.0.1 lib/nadir/config.rb
nadir-1.0.0 lib/nadir/config.rb