Class: HerokuSan::Parser

Inherits:
Object
  • Object
show all
Includes:
Git
Defined in:
lib/heroku_san/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Git

#git_active_branch, #git_clone, #git_named_rev, #git_parsed_tag, #git_push, #git_rev_parse, #git_revision, #git_tag

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/heroku_san/parser.rb', line 6

def settings
  @settings
end

Instance Method Details

#convert_from_heroku_san_formatObject



16
17
18
19
20
# File 'lib/heroku_san/parser.rb', line 16

def convert_from_heroku_san_format
  (settings.delete('apps') || {}).each_pair do |stage, app_name|
    settings[stage] = {'app' => app_name}
  end
end

#each_setting_has_a_config_sectionObject



22
23
24
25
26
27
# File 'lib/heroku_san/parser.rb', line 22

def each_setting_has_a_config_section
  settings.keys.each do |name|
    settings[name] ||= {}
    settings[name]['config'] ||= {}
  end
end

#merge_external_config!(parseable, stages) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/heroku_san/parser.rb', line 29

def merge_external_config!(parseable, stages)
  extra_config = parse_external_config!(parseable.external_configuration)
  return unless extra_config
  stages.each do |stage|
    stage.config.merge!(extra_config[stage.name]) if extra_config[stage.name]
  end
end

#parse(parseable) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/heroku_san/parser.rb', line 7

def parse(parseable)
  @settings = parse_yaml(parseable.config_file)
  convert_from_heroku_san_format
  parseable.external_configuration = @settings.delete 'config_repo'
  each_setting_has_a_config_section
  parseable.configuration = @settings

end

#parse_external_config!(config_repo) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/heroku_san/parser.rb', line 37

def parse_external_config!(config_repo)
  return if config_repo.nil?
  require 'tmpdir'
  Dir.mktmpdir do |dir|
    git_clone config_repo, dir
    parse_yaml File.join(dir, 'config.yml')
  end
end