Module: Rake::FileUtilsExt

### Home Classes Methods

### In Files

- lib/rake/file_utils_ext.rb

### Methods

- #nowrite
- #rake_check_options
- #rake_merge_option
- #rake_output_message
- #verbose
- #when_writing

### Included Modules

- FileUtils

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- command_line_usage.rdoc
- glossary.rdoc
- proto_rake.rdoc
- rakefile.rdoc
- rational.rdoc
- rake-0.4.14.rdoc
- rake-0.4.15.rdoc
- rake-0.5.0.rdoc
- rake-0.5.3.rdoc
- rake-0.5.4.rdoc
- rake-0.6.0.rdoc
- rake-0.7.0.rdoc
- rake-0.7.1.rdoc
- rake-0.7.2.rdoc
- rake-0.7.3.rdoc
- rake-0.8.0.rdoc
- rake-0.8.4.rdoc
- rake-0.8.5.rdoc
- rake-0.8.6.rdoc
- rake-0.8.7.rdoc

### Class/Module Index

Quicksearch

- Rake
- Rake::AltSystem
- Rake::Application
- Rake::Backtrace
- Rake::Cloneable
- Rake::CompositePublisher
- Rake::DSL
- Rake::DefaultLoader
- Rake::EarlyTime
- Rake::FileCreationTask
- Rake::FileList
- Rake::FileTask
- Rake::FileUtilsExt
- Rake::FtpFile
- Rake::FtpUploader
- Rake::InvocationChain
- Rake::InvocationChain::EmptyInvocationChain
- Rake::InvocationExceptionMixin
- Rake::MakefileLoader
- Rake::MultiTask
- Rake::NameSpace
- Rake::PackageTask
- Rake::PseudoStatus
- Rake::RubyForgePublisher
- Rake::RuleRecursionOverflowError
- Rake::SshDirPublisher
- Rake::SshFilePublisher
- Rake::SshFreshDirPublisher
- Rake::Task
- Rake::TaskArgumentError
- Rake::TaskArguments
- Rake::TaskLib
- Rake::TaskManager
- Rake::TestTask
- Rake::TraceOutput
- Rake::Win32
- Rake::Win32::Win32HomeError
- CompositePublisher
- FileUtils
- Module
- Object
- SshDirPublisher
- SshFilePublisher
- SshFreshDirPublisher
- String
- Time

No matching classes.

# Rake::FileUtilsExt

FileUtilsExt provides a custom version of the FileUtils methods that respond to the `verbose` and `nowrite` commands.

### Constants

DEFAULT

### Attributes

nowrite_flag[RW]
verbose_flag[RW]

### Public Instance Methods

nowrite(value=nil) click to toggle source

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.

    # File lib/rake/file_utils_ext.rb, line 77
    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) click to toggle source

Check that the options do not contain options not listed in `optdecl`. An ArgumentError exception is thrown if non-declared options are found.

    # File lib/rake/file_utils_ext.rb, line 133
    def rake_check_options(options, *optdecl)
      h = options.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) click to toggle source

Merge the given options with the default values.

    # File lib/rake/file_utils_ext.rb, line 116
    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) click to toggle source

Send the message to the default rake output (which is $stderr).

    # File lib/rake/file_utils_ext.rb, line 126
    def rake_output_message(message)
      $stderr.puts(message)
    end

verbose(value=nil) click to toggle source

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.

    # File lib/rake/file_utils_ext.rb, line 53
    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) click to toggle source

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.

    # File lib/rake/file_utils_ext.rb, line 107
    def when_writing(msg=nil)
      if FileUtilsExt.nowrite_flag
        $stderr.puts "DRYRUN: #{msg}" if msg
      else
        yield
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.