Module: Figaro

Extended by:
Figaro
Included in:
Figaro
Defined in:
lib/figaro.rb,
lib/figaro/env.rb,
lib/figaro/tasks.rb,
lib/figaro/railtie.rb,
lib/generators/figaro/install/install_generator.rb

Defined Under Namespace

Modules: Generators, Tasks Classes: Env, Railtie

Instance Method Summary collapse

Instance Method Details

#env(custom_environment = nil) ⇒ Object



15
16
17
18
# File 'lib/figaro.rb', line 15

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

#environmentObject



32
33
34
# File 'lib/figaro.rb', line 32

def environment
  Rails.env
end

#pathObject



28
29
30
# File 'lib/figaro.rb', line 28

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

#rawObject



20
21
22
# File 'lib/figaro.rb', line 20

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

#vars(custom_environment = nil) ⇒ Object



9
10
11
12
13
# File 'lib/figaro.rb', line 9

def vars(custom_environment = nil)
  env(custom_environment).map { |key, value|
    "#{key}=#{Shellwords.escape(value)}"
  }.sort.join(" ")
end

#yamlObject



24
25
26
# File 'lib/figaro.rb', line 24

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