Class: Templater::Actions::EmptyDirectory
- Defined in:
- lib/templater/actions/empty_directory.rb
Instance Attribute Summary
Attributes inherited from Action
#destination, #generator, #name, #options, #source
Instance Method Summary collapse
-
#exists? ⇒ Boolean
Checks if the destination file already exists.
-
#identical? ⇒ Boolean
For empty directory this is in fact alias for exists? method.
-
#initialize(generator, name, destination, options = {}) ⇒ EmptyDirectory
constructor
Builds a new Directory.
-
#invoke! ⇒ Object
Renders the template and copies it to the destination.
-
#render ⇒ Object
Returns an empty String: there’s nothing to read from.
-
#revoke! ⇒ Object
removes the destination file.
Methods inherited from Action
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, ={}) self.generator = generator self.name = name self.destination = destination self. = end |
Instance Method Details
#exists? ⇒ Boolean
Checks if the destination file already exists.
Returns
- Boolean
-
true if the file exists, false otherwise.
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.
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 |
#render ⇒ Object
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.(destination)) end |