Class: EY::Templates::EyYml
- Inherits:
-
Object
- Object
- EY::Templates::EyYml
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#existing ⇒ Object
readonly
Returns the value of attribute existing.
-
#existing_config ⇒ Object
readonly
Returns the value of attribute existing_config.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(existing, template = PATH) ⇒ EyYml
constructor
A new instance of EyYml.
- #to_str ⇒ Object (also: #to_s)
- #write(dest) ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/engineyard/templates/ey_yml.rb', line 8 def config @config end |
#existing ⇒ Object (readonly)
Returns the value of attribute existing.
8 9 10 |
# File 'lib/engineyard/templates/ey_yml.rb', line 8 def existing @existing end |
#existing_config ⇒ Object (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 |
#template ⇒ Object (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_str ⇒ Object 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 |