Class: DiceBag::TemplateFile

Inherits:
Object
  • Object
show all
Includes:
DiceBagFile, TemplateHelpers
Defined in:
lib/dice_bag/template_file.rb

Instance Attribute Summary

Attributes included from DiceBagFile

#destination, #file, #filename

Instance Method Summary collapse

Methods included from TemplateHelpers

#ensure_is_private_key, #generate_private_key

Methods included from DiceBagFile

#assert_existence, #should_write?, #write

Constructor Details

#initialize(name) ⇒ TemplateFile

Returns a new instance of TemplateFile.


17
18
19
20
# File 'lib/dice_bag/template_file.rb', line 17

def initialize(name)
  @filename = File.basename(name)
  @file = Project.config_files(name)
end

Instance Method Details

#create_file(config_file, params) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dice_bag/template_file.rb', line 22

def create_file(config_file, params)
  # By passing "<>" we're trimming trailing newlines on lines that are
  # nothing but ERB blocks (see documentation). This is useful for files
  # like mauth_key where we want to control newlines carefully.
  template = ERB.new(File.read(@file), nil, "<>")

  #templates expect a configured object
  configured = Configuration.new
  warning = Warning.new(@filename)
  contents = template.result(binding)

  return unless params[:deploy] || config_file.should_write?(contents)
  config_file.write(contents)
  puts "File '#{config_file.file}' created"
end