Sha256: a78180cd9e3d62dd84d9e6832400ae706ecf473fcbb0c7c9f0d89f0015f46f72

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

require 'yaml'
require 'erb'

module Adjust
  module Core
    class Configuration
      def load(path, environment: nil)
        @environment = environment || default_environment
        @configurations = read_configurations path
      end

      def environment
        @environment ||= default_environment
      end

      def configurations
        @configurations ||= read_configurations
      end

      def active
        configurations[environment]
      end

      def active_environment
        active['environment']
      end

      def tokens(app, event)
        Tokens.new(app, event, active).find
      end

      private

      def default_environment
        ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
      end

      def read_configurations(path = 'config/adjust.yml')
        YAML.load parse read path
      end

      def read(path)
        File.read path
      end

      def parse(file)
        ERB.new(file).result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adjust-0.0.4 lib/adjust/core/configuration.rb
adjust-0.0.3 lib/adjust/core/configuration.rb