Class: Bundler::Thor::Actions::EmptyDirectory
- Inherits:
-
Object
- Object
- Bundler::Thor::Actions::EmptyDirectory
- Defined in:
- lib/bundler/vendor/thor/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
-
#base ⇒ Object
readonly
:nodoc:.
-
#config ⇒ Object
readonly
:nodoc:.
-
#destination ⇒ Object
readonly
:nodoc:.
-
#given_destination ⇒ Object
readonly
:nodoc:.
-
#relative_destination ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#exists? ⇒ Boolean
Checks if the destination file already exists.
-
#initialize(base, destination, config = {}) ⇒ EmptyDirectory
constructor
Initializes given the source and destination.
- #invoke! ⇒ Object
- #revoke! ⇒ Object
Constructor Details
#initialize(base, destination, config = {}) ⇒ EmptyDirectory
Initializes given the source and destination.
Parameters
- base<Bundler::Thor::Base>
-
A Bundler::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.
34 35 36 37 38 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 34 def initialize(base, destination, config = {}) @base = base @config = {:verbose => true}.merge(config) self.destination = destination end |
Instance Attribute Details
#base ⇒ Object (readonly)
:nodoc:
24 25 26 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 24 def base @base end |
#config ⇒ Object (readonly)
:nodoc:
24 25 26 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 24 def config @config end |
#destination ⇒ Object
:nodoc:
24 25 26 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 24 def destination @destination end |
#given_destination ⇒ Object (readonly)
:nodoc:
24 25 26 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 24 def given_destination @given_destination end |
#relative_destination ⇒ Object (readonly)
:nodoc:
24 25 26 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 24 def relative_destination @relative_destination end |
Instance Method Details
#exists? ⇒ Boolean
Checks if the destination file already exists.
Returns
- Boolean
-
true if the file exists, false otherwise.
45 46 47 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 45 def exists? ::File.exist?(destination) end |
#invoke! ⇒ Object
49 50 51 52 53 54 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 49 def invoke! invoke_with_conflict_check do require "fileutils" ::FileUtils.mkdir_p(destination) end end |
#revoke! ⇒ Object
56 57 58 59 60 61 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb', line 56 def revoke! say_status :remove, :red require "fileutils" ::FileUtils.rm_rf(destination) if !pretend? && exists? given_destination end |