Sha256: f7fc19f4369a889c9b6338cdfce50f110473bc68533dfba92eec14dea941e569

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

require 'yaml'

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

    def initialize
      @env         = ENV['ERORR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
      @api_key     = ENV['ERORR_API_KEY']
      @api_url     = 'https://erorr.app/api'.freeze
      @enabled_for = %w(production staging)

      @logger      = Logger.new(STDOUT)
    end

    def validate
      unless @api_key
        logger.warn '[erorr] API-KEY not set, skipping notifications.'

        return false
      end

      unless @enabled_for.include? @env.to_s
        logger.warn "[erorr] 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/erorr.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

6 entries across 6 versions & 1 rubygems

Version Path
erorr-0.2.2 lib/erorr/config.rb
erorr-0.2.1 lib/erorr/config.rb
erorr-0.2.0 lib/erorr/config.rb
erorr-0.1.2 lib/erorr/config.rb
erorr-0.1.1 lib/erorr/config.rb
erorr-0.1.0 lib/erorr/config.rb