Class: EY::Templates::EyYml

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard/templates/ey_yml.rb

Constant Summary collapse

PATH =
Pathname.new(__FILE__).dirname.join('ey.yml.erb').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(existing, template = PATH) ⇒ EyYml

Returns a new instance of EyYml.



10
11
12
13
14
15
16
17
18
19
# File 'lib/engineyard/templates/ey_yml.rb', line 10

def initialize(existing, template=PATH)
  @template = template

  @existing        = existing.dup
  @environments    = @existing.delete('environments') || {}
  @existing_config = @existing.delete('defaults') || {}
  @config          = defaults.merge(@existing_config)

  fix_config!
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/engineyard/templates/ey_yml.rb', line 8

def config
  @config
end

#existingObject (readonly)

Returns the value of attribute existing.



8
9
10
# File 'lib/engineyard/templates/ey_yml.rb', line 8

def existing
  @existing
end

#existing_configObject (readonly)

Returns the value of attribute existing_config.



8
9
10
# File 'lib/engineyard/templates/ey_yml.rb', line 8

def existing_config
  @existing_config
end

#templateObject (readonly)

Returns the value of attribute template.



8
9
10
# File 'lib/engineyard/templates/ey_yml.rb', line 8

def template
  @template
end

Instance Method Details

#to_strObject Also known as: to_s



21
22
23
# File 'lib/engineyard/templates/ey_yml.rb', line 21

def to_str
  ERB.new(template.read, 0, "<>").result(binding)
end

#write(dest) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/engineyard/templates/ey_yml.rb', line 26

def write(dest)
  dest = Pathname.new(dest)
  dir  = dest.dirname
  temp = dir.join("ey.yml.tmp")

  # generate first so we don't overwrite with a failed generation
  output = to_str
  temp.open('w') { |f| f << output }

  FileUtils.mv(dest, dir.join("ey.yml.backup")) if dest.exist?
  FileUtils.mv(temp, dest)
end