Module: Envious

Extended by:
Envious
Included in:
Envious
Defined in:
lib/envious.rb,
lib/envious/railtie.rb,
lib/generators/envious/setup_generator.rb

Defined Under Namespace

Modules: Generators Classes: Railtie

Instance Method Summary collapse

Instance Method Details

#add_to_environment(hash) ⇒ Object



35
36
37
# File 'lib/envious.rb', line 35

def add_to_environment(hash)
  hash.each { |key, value| ENV[key.to_s] = value.to_s unless ENV.key?(key.to_s) }
end

#default_varsObject



27
28
29
# File 'lib/envious.rb', line 27

def default_vars()
  yaml.reject { |_, v| Hash === v }
end

#environmentObject



23
24
25
# File 'lib/envious.rb', line 23

def environment
  Rails.env.to_s
end

#environment_varsObject



31
32
33
# File 'lib/envious.rb', line 31

def environment_vars
  yaml.fetch(environment, {})
end

#fileObject



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

def file 
  @file ||= Rails.root.join('config/environment_vars.yml')
end

#load_envObject



11
12
13
# File 'lib/envious.rb', line 11

def load_env()
  add_to_environment(default_vars.merge(environment_vars))
end

#vars_for_herokuObject



6
7
8
9
# File 'lib/envious.rb', line 6

def vars_for_heroku()
  env_vars = default_vars.merge(environment_vars)
  env_vars = env_vars.map { |k, v| "#{k}=#{v}"}.join(' ')
end

#yamlObject



19
20
21
# File 'lib/envious.rb', line 19

def yaml
  @yaml ||= File.exist?(file) ? YAML.load(File.read(file)) : {}
end