Sha256: 5c48dc34c28c8a668535a4ae885ad62fa858d036447868b8fcb3878de92b6f24

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

require "shellwords"
require "figaro/env"
require "figaro/railtie"
require "figaro/tasks"

module Figaro
  extend self

  def vars(custom_environment = nil)
    env(custom_environment).map { |key, value|
      "#{key}=#{Shellwords.escape(value)}"
    }.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) ? ERB.new(File.read(path)).result : 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.nil? ? nil : v.to_s; h }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
figaro-0.7.0 lib/figaro.rb