class Thor::Actions::EmptyDirectory
:nodoc:
and Michael S. Klishin under MIT LICENSE.
This implementation is based in Templater actions, created by Jonas Nicklas
other actions like create_file and directory.
Class which holds create directory logic. This is the base class for
def convert_encoded_instructions(filename)
The method referenced can be either public or private.
user.rb
return value (should be String) of #file_name:
It calls #file_name from the base and replaces %-string with the
%file_name%.rb
Filenames in the encoded form are converted. If you have a file:
def convert_encoded_instructions(filename) filename.gsub(/%(.*?)%/) do |initial_string| method = $1.strip base.respond_to?(method, true) ? base.send(method) : initial_string end end
def destination=(destination)
given_destination #=> baz
relative_destination #=> bar/baz
destination #=> dest/bar/baz
end
empty_directory "baz"
inside "bar" do
are related in the following way:
"dest". The destination, given_destination and relative_destination
script is being executed on "dest", it sets the destination root to
It also stores the given and relative destination. Let's suppose our
Sets the absolute destination value from a relative destination value.
def destination=(destination) if destination @given_destination = convert_encoded_instructions(destination.to_s) @destination = ::File.expand_path(@given_destination, base.destination_root) @relative_destination = base.relative_to_original_destination_root(@destination) end end
def exists?
Boolean:: true if the file exists, false otherwise.
==== Returns
Checks if the destination file already exists.
def exists? ::File.exists?(destination) end
def initialize(base, destination, config={})
config
destination
source
base
==== Parameters
Initializes given the source and destination.
def initialize(base, destination, config={}) @base, @config = base, { :verbose => true }.merge(config) self.destination = destination end
def invoke!
def invoke! invoke_with_conflict_check do ::FileUtils.mkdir_p(destination) end end
def invoke_with_conflict_check(&block)
conditions are met.
Receives a hash of options and just execute the block if some
def invoke_with_conflict_check(&block) if exists? on_conflict_behavior(&block) else say_status :create, :green block.call unless pretend? end destination end
def on_conflict_behavior(&block)
What to do when the destination file already exists.
def on_conflict_behavior(&block) say_status :exist, :blue end
def pretend?
Shortcut for pretend.
def pretend? base.options[:pretend] end
def revoke!
def revoke! say_status :remove, :red ::FileUtils.rm_rf(destination) if !pretend? && exists? given_destination end
def say_status(status, color)
Shortcut to say_status shell method.
def say_status(status, color) base.shell.say_status status, relative_destination, color if config[:verbose] end