Class: Codebuild::Setting
- Inherits:
-
Object
- Object
- Codebuild::Setting
- Extended by:
- Memoist
- Defined in:
- lib/codebuild/setting.rb
Instance Method Summary collapse
-
#cb_env ⇒ Object
Resolves infinite problem since Codebuild.env can be determined from CB_ENV or settings.yml files.
-
#data ⇒ Object
data contains the settings.yml config.
-
#initialize(check_codebuild_project = true) ⇒ Setting
constructor
A new instance of Setting.
Constructor Details
#initialize(check_codebuild_project = true) ⇒ Setting
Returns a new instance of Setting.
7 8 9 |
# File 'lib/codebuild/setting.rb', line 7 def initialize(check_codebuild_project=true) @check_codebuild_project = check_codebuild_project end |
Instance Method Details
#cb_env ⇒ Object
Resolves infinite problem since Codebuild.env can be determined from CB_ENV or settings.yml files. When ufo is determined from settings it should not called Codebuild.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/codebuild/setting.rb', line 36 def cb_env settings = YAML.load_file("#{cb_root}/.codebuild/settings.yml") env = settings.find do |_env, section| section ||= {} ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile'] end cb_env = env.first if env cb_env = ENV['CB_ENV'] if ENV['CB_ENV'] # highest precedence cb_env || 'development' end |
#data ⇒ Object
data contains the settings.yml config. The order or precedence for settings is the project ufo/settings.yml and then the ~/.codebuild/settings.yml.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/codebuild/setting.rb', line 13 def data Codebuild.check_codebuild_project! if @check_codebuild_project return {} unless File.exist?(project_settings_path) # project based settings files project = load_file(project_settings_path) user_file = "#{ENV['HOME']}/.codebuild/settings.yml" user = File.exist?(user_file) ? YAML.load_file(user_file) : {} default_file = File.("default/settings.yml", __dir__) default = load_file(default_file) all_envs = default.deep_merge(user.deep_merge(project)) all_envs = merge_base(all_envs) data = all_envs[cb_env] || all_envs["base"] || {} data.deep_symbolize_keys end |