Class: Thor::Actions::EmptyDirectory

Inherits:
Object
  • Object
show all
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

CreateFile, Directory, InjectIntoFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, destination, config = {}) ⇒ EmptyDirectory

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.



34
35
36
37
# File 'lib/thor/actions/empty_directory.rb', line 34

def initialize(base, destination, config = {})
  @base, @config   = base, {:verbose => true}.merge(config)
  self.destination = destination
end

Instance Attribute Details

#baseObject (readonly)

:nodoc:



24
25
26
# File 'lib/thor/actions/empty_directory.rb', line 24

def base
  @base
end

#configObject (readonly)

:nodoc:



24
25
26
# File 'lib/thor/actions/empty_directory.rb', line 24

def config
  @config
end

#destinationObject

:nodoc:



24
25
26
# File 'lib/thor/actions/empty_directory.rb', line 24

def destination
  @destination
end

#given_destinationObject (readonly)

:nodoc:



24
25
26
# File 'lib/thor/actions/empty_directory.rb', line 24

def given_destination
  @given_destination
end

#relative_destinationObject (readonly)

:nodoc:



24
25
26
# File '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.



44
45
46
# File 'lib/thor/actions/empty_directory.rb', line 44

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

#invoke!Object



48
49
50
51
52
# File 'lib/thor/actions/empty_directory.rb', line 48

def invoke!
  invoke_with_conflict_check do
    ::FileUtils.mkdir_p(destination)
  end
end

#revoke!Object



54
55
56
57
58
# File 'lib/thor/actions/empty_directory.rb', line 54

def revoke!
  say_status :remove, :red
  ::FileUtils.rm_rf(destination) if !pretend? && exists?
  given_destination
end