Class: Hobber::RenderedObjectSaver

Inherits:
Object
  • Object
show all
Includes:
FileUtils, Thor::Shell
Defined in:
lib/hobber/rendered_object_saver.rb

Instance Method Summary collapse

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

#saveObject



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