Sha256: 2c73c3407befb2f6b141efdb17360ace728d107cf212a2065350df76d058e456

Contents?: true

Size: 652 Bytes

Versions: 3

Compression:

Stored size: 652 Bytes

Contents

require 'ostruct'

module SlonikMigration
  class Config
    class << self
      def load
        file = config_file
        env = ENV['RAILS_ENV'] || 'development'

        hash = if File.exist?(file)
                 YAML.load(ERB.new(IO.read(file)).result)[env]
               else
                 {}
               end
        OpenStruct.new(hash).freeze
      end

      private

      def config_file
        if ENV['CONFIG_FILE']
          ENV['CONFIG_FILE']
        elsif defined?(Rails)
          Rails.root.join('config/slonik.yml').to_s
        else
          File.join(Dir.pwd, 'config/slonik.yml')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slonik_migration-1.1.3 lib/slonik_migration/config.rb
slonik_migration-1.1.2 lib/slonik_migration/config.rb
slonik_migration-1.1.1 lib/slonik_migration/config.rb