Sha256: 8ae56412674909fe012be8615143a9315cb4ad944ad61e85dd6f754640b977c8

Contents?: true

Size: 780 Bytes

Versions: 1

Compression:

Stored size: 780 Bytes

Contents

require "figaro/env"
require "figaro/railtie"

module Figaro
  extend self

  def vars(custom_environment = nil)
    env(custom_environment).map{|k,v| "#{k}=#{v}" }.sort.join(" ")
  end

  def env(custom_environment = nil)
    environment = (custom_environment || self.environment).to_s
    Figaro::Env.from(stringify(flatten(raw).merge(raw.fetch(environment, {}))))
  end

  def raw
    @raw ||= yaml && YAML.load(yaml) || {}
  end

  def yaml
    @yaml ||= File.exist?(path) ? File.read(path) : nil
  end

  def path
    @path ||= Rails.root.join("config/application.yml")
  end

  def environment
    Rails.env
  end

  private

  def flatten(hash)
    hash.reject{|_,v| Hash === v }
  end

  def stringify(hash)
    hash.inject({}){|h,(k,v)| h[k.to_s] = v.to_s; h }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
figaro-0.5.0 lib/figaro.rb