Templater::Actions::File

Public Class Methods

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

Builds a new file.

Parameters

generator

The generator

name

The name of this file

source

Full path to the source of this file

destination

Full path to the destination of this file

optionsSymbol}

Options, including callbacks.

    # File lib/templater/actions/file.rb, line 13
13:       def initialize(generator, name, source, destination, options={})
14:         self.generator = generator
15:         self.name = name
16:         self.source = source
17:         self.destination = destination
18:         self.options = options
19:       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
33:       def exists?
34:         ::File.exists?(destination)
35:       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
41:       def identical?
42:         exists? && ::FileUtils.identical?(source, destination)
43:       end
invoke!() click to toggle source

Renders the template and copies it to the destination.

    # File lib/templater/actions/file.rb, line 46
46:       def invoke!
47:         callback(:before)
48:         ::FileUtils.mkdir_p(::File.dirname(destination))
49:         ::FileUtils.cp_r(source, destination)
50:         callback(:after)
51:       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
25:       def render
26:         ::File.read(source)
27:       end
revoke!() click to toggle source

removes the destination file

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.