Module: Rake::FileUtilsExt
- Extended by:
- FileUtilsExt
- Includes:
- FileUtils
- Included in:
- Rake, DSL, FileUtilsExt
- Defined in:
- lib/rake/file_utils_ext.rb
Overview
FileUtilsExt provides a custom version of the FileUtils methods that respond to the verbose
and nowrite
commands.
Constant Summary collapse
- DEFAULT =
Object.new
Constants included from FileUtils
FileUtils::LN_SUPPORTED, FileUtils::RUBY
Class Attribute Summary collapse
-
.nowrite_flag ⇒ Object
Returns the value of attribute nowrite_flag.
-
.verbose_flag ⇒ Object
Returns the value of attribute verbose_flag.
Instance Method Summary collapse
-
#nowrite(value = nil) ⇒ Object
Get/set the nowrite flag controlling output from the FileUtils utilities.
-
#rake_check_options(options, *optdecl) ⇒ Object
Check that the options do not contain options not listed in
optdecl
. -
#rake_merge_option(args, defaults) ⇒ Object
Merge the given options with the default values.
-
#rake_output_message(message) ⇒ Object
Send the message to the default rake output (which is $stderr).
-
#verbose(value = nil) ⇒ Object
Get/set the verbose flag controlling output from the FileUtils utilities.
-
#when_writing(msg = nil) ⇒ Object
Use this function to prevent potentially destructive ruby code from running when the :nowrite flag is set.
Methods included from FileUtils
#ruby, #safe_ln, #sh, #split_all
Class Attribute Details
.nowrite_flag ⇒ Object
Returns the value of attribute nowrite_flag
13 14 15 |
# File 'lib/rake/file_utils_ext.rb', line 13 def nowrite_flag @nowrite_flag end |
.verbose_flag ⇒ Object
Returns the value of attribute verbose_flag
13 14 15 |
# File 'lib/rake/file_utils_ext.rb', line 13 def verbose_flag @verbose_flag end |
Instance Method Details
#nowrite(value = nil) ⇒ Object
Get/set the nowrite flag controlling output from the FileUtils utilities. If verbose is true, then the utility method is echoed to standard output.
Examples:
nowrite # return the current value of the
# nowrite flag
nowrite(v) # set the nowrite flag to _v_.
nowrite(v) { code } # Execute code with the nowrite flag set
# temporarily to _v_. Return to the
# original value when code is done.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rake/file_utils_ext.rb', line 79 def nowrite(value=nil) oldvalue = FileUtilsExt.nowrite_flag FileUtilsExt.nowrite_flag = value unless value.nil? if block_given? begin yield ensure FileUtilsExt.nowrite_flag = oldvalue end end oldvalue end |
#rake_check_options(options, *optdecl) ⇒ Object
Check that the options do not contain options not listed in optdecl
. An ArgumentError exception is thrown if non-declared options are found.
135 136 137 138 139 140 141 |
# File 'lib/rake/file_utils_ext.rb', line 135 def (, *optdecl) h = .dup optdecl.each do |name| h.delete name end raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty? end |
#rake_merge_option(args, defaults) ⇒ Object
Merge the given options with the default values.
118 119 120 121 122 123 124 125 |
# File 'lib/rake/file_utils_ext.rb', line 118 def rake_merge_option(args, defaults) if Hash === args.last defaults.update(args.last) args.pop end args.push defaults args end |
#rake_output_message(message) ⇒ Object
Send the message to the default rake output (which is $stderr).
128 129 130 |
# File 'lib/rake/file_utils_ext.rb', line 128 def () $stderr.puts() end |
#verbose(value = nil) ⇒ Object
Get/set the verbose flag controlling output from the FileUtils utilities. If verbose is true, then the utility method is echoed to standard output.
Examples:
verbose # return the current value of the
# verbose flag
verbose(v) # set the verbose flag to _v_.
verbose(v) { code } # Execute code with the verbose flag set
# temporarily to _v_. Return to the
# original value when code is done.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rake/file_utils_ext.rb', line 55 def verbose(value=nil) oldvalue = FileUtilsExt.verbose_flag FileUtilsExt.verbose_flag = value unless value.nil? if block_given? begin yield ensure FileUtilsExt.verbose_flag = oldvalue end end FileUtilsExt.verbose_flag end |
#when_writing(msg = nil) ⇒ Object
Use this function to prevent potentially destructive ruby code from running when the :nowrite flag is set.
Example:
when_writing("Building Project") do
project.build
end
The following code will build the project under normal conditions. If the nowrite(true) flag is set, then the example will print:
DRYRUN: Building Project
instead of actually building the project.
109 110 111 112 113 114 115 |
# File 'lib/rake/file_utils_ext.rb', line 109 def when_writing(msg=nil) if FileUtilsExt.nowrite_flag $stderr.puts "DRYRUN: #{msg}" if msg else yield end end |