Class: Hobber::RenderedObjectSaver
- Inherits:
-
Object
- Object
- Hobber::RenderedObjectSaver
- Includes:
- FileUtils, Thor::Shell
- Defined in:
- lib/hobber/rendered_object_saver.rb
Instance Method Summary collapse
-
#initialize(rendered_object, safe_mode = false, logger = Logger.new(STDOUT)) ⇒ RenderedObjectSaver
constructor
A new instance of RenderedObjectSaver.
- #save ⇒ Object
Constructor Details
#initialize(rendered_object, safe_mode = false, logger = Logger.new(STDOUT)) ⇒ RenderedObjectSaver
Returns a new instance of RenderedObjectSaver.
10 11 12 13 14 |
# File 'lib/hobber/rendered_object_saver.rb', line 10 def initialize(rendered_object, safe_mode=false, logger=Logger.new(STDOUT)) @rendered_object = rendered_object @safe_mode = safe_mode @logger = logger end |
Instance Method Details
#save ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hobber/rendered_object_saver.rb', line 16 def save path_name = Pathname.new(@rendered_object.path) if @safe_mode && path_name.exist? && !file_collision(path_name) return end mkdir_p(path_name.dirname) @logger.info("writing target [#{path_name}] ..") File.open(@rendered_object.path, 'w') do |f| f.write(@rendered_object.data) end end |