Class: Pipedream::Setting

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

Instance Method Summary collapse

Constructor Details

#initialize(check_pipedream_project = true) ⇒ Setting

Returns a new instance of Setting.



7
8
9
# File 'lib/pipedream/setting.rb', line 7

def initialize(check_pipedream_project=true)
  @check_pipedream_project = check_pipedream_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 ~/.pipedream/settings.yml.



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

def data
  Pipedream.check_pipedream_project! if @check_pipedream_project
  return {} unless File.exist?(project_settings_path)

  # project based settings files
  project = load_file(project_settings_path)

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

  default_file = File.expand_path("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[pipe_env] || {}
  base_data = all_envs["base"] || {}
  data = base_data.merge(env_data)

  data.deep_symbolize_keys
end

#pipe_envObject

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pipedream/setting.rb', line 40

def pipe_env
  path = "#{cb_root}/.pipedream/settings.yml"
  if File.exist?(path)
    settings = YAML.load_file(path)
    env = settings.find do |_env, section|
      section ||= {}
      ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile']
    end
  end

  pipe_env = env.first if env
  pipe_env = ENV['PIPE_ENV'] if ENV['PIPE_ENV'] # highest precedence
  pipe_env || 'development'
end