Class: Efail::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/efail/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Renderer



5
6
7
8
9
10
# File 'lib/efail/renderer.rb', line 5

def initialize options
  @dest     = options[:dest]
  @force    = options[:force_overwrite]
  @document = ::Roadie::Document.new File.open(options[:src]).read
  @document.url_options = { host: options[:url].host, protocol: options[:url].scheme } unless options[:url].nil?
end

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/efail/renderer.rb', line 12

def render
  if !@force && (File.exists? (File.expand_path @dest))
    puts "#{@dest} already exists. Overwrite with the --force flag."
    exit
  end

  file = File.new @dest, 'w'
  file.write @document.transform
  file.close
end