Class: Thor::Actions::EmptyDirectory
- Inherits:
-
Object
- Object
- Thor::Actions::EmptyDirectory
- Defined in:
- lib/thor/actions/empty_directory.rb
Overview
Class which holds create directory logic. This is the base class for other actions like create_file and directory.
This implementation is based in Templater actions, created by Jonas Nicklas and Michael S. Klishin under MIT LICENSE.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) base
readonly
:nodoc:.
-
- (Object) config
readonly
:nodoc:.
-
- (Object) destination
readonly
:nodoc:.
-
- (Object) given_destination
readonly
:nodoc:.
-
- (Object) relative_destination
readonly
:nodoc:.
Instance Method Summary (collapse)
-
- (Boolean) exists?
Checks if the destination file already exists.
-
- (EmptyDirectory) initialize(base, destination, config = {})
constructor
Initializes given the source and destination.
- - (Object) invoke!
- - (Object) revoke!
Constructor Details
- (EmptyDirectory) initialize(base, destination, config = {})
Initializes given the source and destination.
Parameters
base<Thor::Base> |
A Thor::Base instance |
source<String> |
Relative path to the source of this file |
destination<String> |
Relative path to the destination of this file |
config<Hash> |
give :verbose => false to not log the status. |
35 36 37 38 |
# File 'lib/thor/actions/empty_directory.rb', line 35 def initialize(base, destination, config={}) @base, @config = base, { :verbose => true }.merge(config) self.destination = destination end |
Instance Attribute Details
- (Object) base (readonly)
:nodoc:
25 26 27 |
# File 'lib/thor/actions/empty_directory.rb', line 25 def base @base end |
- (Object) config (readonly)
:nodoc:
25 26 27 |
# File 'lib/thor/actions/empty_directory.rb', line 25 def config @config end |
- (Object) destination
:nodoc:
25 26 27 |
# File 'lib/thor/actions/empty_directory.rb', line 25 def destination @destination end |
- (Object) given_destination (readonly)
:nodoc:
25 26 27 |
# File 'lib/thor/actions/empty_directory.rb', line 25 def given_destination @given_destination end |
- (Object) relative_destination (readonly)
:nodoc:
25 26 27 |
# File 'lib/thor/actions/empty_directory.rb', line 25 def relative_destination @relative_destination end |
Instance Method Details
- (Boolean) exists?
Checks if the destination file already exists.
Returns
Boolean |
true if the file exists, false otherwise. |
45 46 47 |
# File 'lib/thor/actions/empty_directory.rb', line 45 def exists? ::File.exists?(destination) end |
- (Object) invoke!
49 50 51 52 53 |
# File 'lib/thor/actions/empty_directory.rb', line 49 def invoke! invoke_with_conflict_check do ::FileUtils.mkdir_p(destination) end end |
- (Object) revoke!
55 56 57 58 59 |
# File 'lib/thor/actions/empty_directory.rb', line 55 def revoke! say_status :remove, :red ::FileUtils.rm_rf(destination) if !pretend? && exists? given_destination end |