Class: GhostWriter::Writer::Base
- Inherits:
-
Object
- Object
- GhostWriter::Writer::Base
- Defined in:
- lib/ghost_writer/writer/base.rb
Instance Method Summary collapse
-
#initialize(document, options = {}) ⇒ Base
constructor
A new instance of Base.
- #write_file ⇒ Object
Constructor Details
#initialize(document, options = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/ghost_writer/writer/base.rb', line 5 def initialize(document, = {}) @document = document @overwrite = [:overwrite] || false end |
Instance Method Details
#write_file ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ghost_writer/writer/base.rb', line 10 def write_file unless File.exist?(File.dirname(@document.basename)) FileUtils.mkdir_p(File.dirname(@document.basename)) end mode = @overwrite ? "w" : "a" File.open("#{@document.basename}.#{extname}", mode) do |f| f.write template.result(@document.instance_eval { binding }) end end |