class Templater::Actions::File

Public Class Methods

new(generator, name, source, destination, options={}) click to toggle source

Builds a new file.

Parameters

generator<Object>

The generator

name<Symbol>

The name of this file

source<String>

Full path to the source of this file

destination<String>

Full path to the destination of this file

options<Hash{Symbol=>Symbol}

Options, including callbacks.

# File lib/templater/actions/file.rb, line 13
def initialize(generator, name, source, destination, options={})
  self.generator = generator
  self.name = name
  self.source = source
  self.destination = destination
  self.options = options
end

Public Instance Methods

exists?() click to toggle source

Checks if the destination file already exists.

Returns

Boolean

true if the file exists, false otherwise.

# File lib/templater/actions/file.rb, line 33
def exists?
  ::File.exists?(destination)
end
identical?() click to toggle source

Checks if the content of the file at the destination is identical to the rendered result.

Returns

Boolean

true if it is identical, false otherwise.

# File lib/templater/actions/file.rb, line 41
def identical?
  exists? && ::FileUtils.identical?(source, destination)
end
invoke!() click to toggle source

Renders the template and copies it to the destination.

# File lib/templater/actions/file.rb, line 46
def invoke!
  callback(:before)
  ::FileUtils.mkdir_p(::File.dirname(destination))
  ::FileUtils.cp_r(source, destination)
  callback(:after)
end
render() click to toggle source

Returns the contents of the source file as a String

Returns

String

The source file.

# File lib/templater/actions/file.rb, line 25
def render
  ::File.read(source)
end
revoke!() click to toggle source

removes the destination file

# File lib/templater/actions/file.rb, line 54
def revoke!
  ::FileUtils.rm_r(destination, :force => true)
end