Class: DiceBag::TemplateFile
- Inherits:
-
Object
- Object
- DiceBag::TemplateFile
- Includes:
- DiceBagFile, TemplateHelpers
- Defined in:
- lib/dice_bag/template_file.rb
Instance Attribute Summary
Attributes included from DiceBagFile
Instance Method Summary collapse
- #create_file(config_file) ⇒ Object
-
#initialize(name) ⇒ TemplateFile
constructor
A new instance of TemplateFile.
Methods included from TemplateHelpers
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 = name end |
Instance Method Details
#create_file(config_file) ⇒ 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) # 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 config_file.should_write?(contents) config_file.write(contents) puts "file #{config_file.file} created" end |