Class: KISSGen::Template
- Inherits:
-
Object
- Object
- KISSGen::Template
- Defined in:
- lib/kissgen/template.rb
Defined Under Namespace
Classes: SourceFileNotFoundError
Instance Attribute Summary collapse
-
#copy_path ⇒ Object
readonly
Returns the value of attribute copy_path.
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#create ⇒ Object
This will create the file with parsed data in the destination directory.
-
#delete ⇒ Object
Will remove the file if it exists.
- #full_copy_path ⇒ Object
- #full_source_path ⇒ Object
-
#initialize(generator, path, copy_path) ⇒ Template
constructor
A new instance of Template.
-
#output ⇒ Object
Parsed ERB output.
- #source_path_check ⇒ Object
Constructor Details
#initialize(generator, path, copy_path) ⇒ Template
Returns a new instance of Template.
6 7 8 9 10 11 12 |
# File 'lib/kissgen/template.rb', line 6 def initialize(generator, path, copy_path) @generator = generator @path = path @copy_path = copy_path source_path_check end |
Instance Attribute Details
#copy_path ⇒ Object (readonly)
Returns the value of attribute copy_path.
4 5 6 |
# File 'lib/kissgen/template.rb', line 4 def copy_path @copy_path end |
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
4 5 6 |
# File 'lib/kissgen/template.rb', line 4 def generator @generator end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/kissgen/template.rb', line 4 def path @path end |
Instance Method Details
#create ⇒ Object
This will create the file with parsed data in the destination directory
27 28 29 30 31 32 33 |
# File 'lib/kissgen/template.rb', line 27 def create puts copy_path FileUtils.mkdir_p(File.dirname(full_copy_path)) @file = File.new full_copy_path, "w" @file.print output # Taylor OWNZ @file.close end |
#delete ⇒ Object
Will remove the file if it exists
41 42 43 44 |
# File 'lib/kissgen/template.rb', line 41 def delete raise "Need to create the file first. File: #{@file.inspect}" unless @file File.delete(full_copy_path) end |
#full_copy_path ⇒ Object
22 23 24 |
# File 'lib/kissgen/template.rb', line 22 def full_copy_path File.join @generator.copy_path, @copy_path end |
#full_source_path ⇒ Object
18 19 20 |
# File 'lib/kissgen/template.rb', line 18 def full_source_path File.join @generator.path, @path end |
#output ⇒ Object
Parsed ERB output
36 37 38 |
# File 'lib/kissgen/template.rb', line 36 def output ERB.new(IO.read(full_source_path)).result end |
#source_path_check ⇒ Object
14 15 16 |
# File 'lib/kissgen/template.rb', line 14 def source_path_check raise SourceFileNotFoundError, "Template source file could not be found at #{full_source_path}" unless File.exists?(full_source_path) end |