Class: Cody::Setting
Instance Method Summary collapse
-
#cb_env ⇒ Object
Resolves infinite problem since Cody.env can be determined from CODY_ENV or settings.yml files.
-
#data ⇒ Object
data contains the settings.yml config.
-
#initialize(check_cody_project = true) ⇒ Setting
constructor
A new instance of Setting.
Constructor Details
#initialize(check_cody_project = true) ⇒ Setting
Returns a new instance of Setting.
7 8 9 |
# File 'lib/cody/setting.rb', line 7 def initialize(check_cody_project=true) @check_cody_project = check_cody_project end |
Instance Method Details
#cb_env ⇒ Object
Resolves infinite problem since Cody.env can be determined from CODY_ENV or settings.yml files. When ufo is determined from settings it should not called Cody.env since that in turn calls Settings.new.data which can then cause an infinite loop.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cody/setting.rb', line 39 def cb_env path = "#{cb_root}/.cody/settings.yml" if File.exist?(path) settings = YAML.load_file(path) settings = {} unless settings.is_a?(Hash) # in case YAML has nothing but comments env = settings.find do |_env, section| section ||= {} ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile'] end end cb_env = env.first if env cb_env = ENV['CODY_ENV'] if ENV['CODY_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 ~/.cody/settings.yml.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cody/setting.rb', line 13 def data Cody.check_cody_project! if @check_cody_project return {} unless File.exist?(project_settings_path) # project based settings files project = load_file(project_settings_path) user_file = "#{ENV['HOME']}/.cody/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) env_data = all_envs[cb_env] || {} base_data = all_envs["base"] || {} data = base_data.merge(env_data) data.deep_symbolize_keys end |