Class: Pkgr::Templates::FileTemplate
- Inherits:
-
Object
- Object
- Pkgr::Templates::FileTemplate
- Defined in:
- lib/pkgr/templates/file_template.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(target, source, opts = {}) ⇒ FileTemplate
constructor
A new instance of FileTemplate.
-
#install(template_binding) ⇒ Object
Assumes that the current working directory is correct.
Constructor Details
#initialize(target, source, opts = {}) ⇒ FileTemplate
Returns a new instance of FileTemplate.
8 9 10 11 12 |
# File 'lib/pkgr/templates/file_template.rb', line 8 def initialize(target, source, opts = {}) @target = target @source = source @opts = opts end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/pkgr/templates/file_template.rb', line 6 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/pkgr/templates/file_template.rb', line 6 def target @target end |
Instance Method Details
#install(template_binding) ⇒ Object
Assumes that the current working directory is correct
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pkgr/templates/file_template.rb', line 15 def install(template_binding) make_dir File.open(target, "w+") do |f| if source.respond_to?(:path) && File.extname(source) == ".erb" f << ERB.new(source.read).result(template_binding) else f << source.read end end FileUtils.chmod mode, target end |