class Bundler::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) return unless 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
def exists?
Boolean:: true if the file exists, false otherwise.
==== Returns
Checks if the destination file already exists.
def exists? ::File.exist?(destination) end
def initialize(base, destination, config = {})
config
destination
source
base
==== Parameters
Initializes given the source and destination.
def initialize(base, destination, config = {}) @base = base @config = {:verbose => true}.merge(config) self.destination = destination end
def invoke!
def invoke! invoke_with_conflict_check do require "fileutils" ::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 yield unless pretend? say_status :create, :green end destination rescue Errno::EISDIR, Errno::EEXIST on_file_clash_behavior end
def on_conflict_behavior
What to do when the destination file already exists.
def on_conflict_behavior say_status :exist, :blue end
def on_file_clash_behavior
def on_file_clash_behavior say_status :file_clash, :red end
def pretend?
Shortcut for pretend.
def pretend? base.options[:pretend] end
def revoke!
def revoke! say_status :remove, :red require "fileutils" ::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