Class: Templater::Actions::EmptyDirectory

Inherits:
Action
  • Object
show all
Defined in:
lib/templater/actions/empty_directory.rb

Instance Attribute Summary

Attributes inherited from Action

#destination, #generator, #name, #options, #source

Instance Method Summary collapse

Methods inherited from Action

#relative_destination

Constructor Details

#initialize(generator, name, destination, options = {}) ⇒ EmptyDirectory

Builds a new Directory

Parameters

generator<Object>

The generator

name<Symbol>

The name of this directory

destination<String>

Full path to the destination of this directory

options<HashSymbol=>Symbol

Options, including callbacks.



12
13
14
15
16
17
# File 'lib/templater/actions/empty_directory.rb', line 12

def initialize(generator, name, destination, options={})
  self.generator = generator
  self.name = name
  self.destination = destination
  self.options = options
end

Instance Method Details

#exists?Boolean

Checks if the destination file already exists.

Returns

Boolean

true if the file exists, false otherwise.

Returns:

  • (Boolean)


31
32
33
# File 'lib/templater/actions/empty_directory.rb', line 31

def exists?
  ::File.exists?(destination)
end

#identical?Boolean

For empty directory this is in fact alias for exists? method.

Returns

Boolean

true if it is identical, false otherwise.

Returns:

  • (Boolean)


39
40
41
# File 'lib/templater/actions/empty_directory.rb', line 39

def identical?
  exists?
end

#invoke!Object

Renders the template and copies it to the destination.



44
45
46
47
48
# File 'lib/templater/actions/empty_directory.rb', line 44

def invoke!
  callback(:before)
  ::FileUtils.mkdir_p(destination)
  callback(:after)
end

#renderObject

Returns an empty String: there’s nothing to read from.

Returns

String

The source file.



23
24
25
# File 'lib/templater/actions/empty_directory.rb', line 23

def render
  ''
end

#revoke!Object

removes the destination file



51
52
53
# File 'lib/templater/actions/empty_directory.rb', line 51

def revoke!
  ::FileUtils.rm_rf(::File.expand_path(destination))
end