Class: Ufo::Setting

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/ufo/setting.rb,
lib/ufo/setting/profile.rb

Defined Under Namespace

Classes: Profile

Instance Method Summary collapse

Constructor Details

#initialize(check_ufo_project = true) ⇒ Setting

Returns a new instance of Setting.



6
7
8
# File 'lib/ufo/setting.rb', line 6

def initialize(check_ufo_project=true)
  @check_ufo_project = check_ufo_project
end

Instance Method Details

#dataObject

data contains the settings.yml config. The order or precedence for settings is the project ufo/settings.yml and then the ~/.ufo/settings.yml.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ufo/setting.rb', line 12

def data
  if @check_ufo_project && !File.exist?(project_settings_path)
    Ufo.check_ufo_project!
  end

  # project based settings files
  project = load_file(project_settings_path)

  user_file = "#{ENV['HOME']}/.ufo/settings.yml"
  user = File.exist?(user_file) ? YAML.load_file(user_file) : {}

  default_file = File.expand_path("../default/settings.yml", __FILE__)
  default = load_file(default_file)

  all_envs = default.deep_merge(user.deep_merge(project))
  all_envs = merge_base(all_envs)
  data = all_envs[ufo_env] || all_envs["base"] || {}
  data.deep_symbolize_keys
end

#ufo_envObject

Resovles infinite problem since Ufo.env can be determined from UFO_ENV or settings.yml files. When ufo is determined from settings it should not called Ufo.env since that in turn calls Settings.new.data which can then cause an infinite loop.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ufo/setting.rb', line 36

def ufo_env
  settings = YAML.load_file("#{Ufo.root}/.ufo/settings.yml")
  env = settings.find do |_env, section|
    section ||= {}
    ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile']
  end

  ufo_env = env.first if env
  ufo_env = ENV['UFO_ENV'] if ENV['UFO_ENV'] # highest precedence
  ufo_env || 'development'
end