class Bake::Blocks::FileUtil

Public Class Methods

new(config, type, projectDir) click to toggle source
# File lib/blocks/fileutil.rb, line 8
def initialize(config, type, projectDir)
  @arg1 = config.name
  @arg2 = config.respond_to?(:to) ? config.to : nil
  @type = type
  @projectDir = projectDir
  @echo = (config.echo != "off")
  if !@arg1 || @arg1.empty?
    Bake.formatter.printError("Error: source of file-step must not be empty")
    ExitHelper.exit(1)
  elsif [:copy, :move].include?(@type) && (!@arg2 || @arg2.empty?)
    Bake.formatter.printError("Error: target of file-step must not be empty")
    ExitHelper.exit(1)
  end
end

Public Instance Methods

clean() click to toggle source
# File lib/blocks/fileutil.rb, line 61
def clean
  # nothing to do here
  return true
end
cleanStep() click to toggle source
# File lib/blocks/fileutil.rb, line 57
def cleanStep
  return run()
end
execute() click to toggle source
# File lib/blocks/fileutil.rb, line 45
def execute
  return run()
end
exitStep() click to toggle source
# File lib/blocks/fileutil.rb, line 53
def exitStep
  return run()
end
run() click to toggle source
# File lib/blocks/fileutil.rb, line 23
def run
  Dir.chdir(@projectDir) do
    if @type == :touch
      puts "Touching #{@arg1}" if @echo
      FileUtils.touch(@arg1)
    elsif @type == :move
      puts "Moving #{@arg1} to #{@arg2}" if @echo
      Dir.glob(@arg1).each {|f| FileUtils.mv(f, @arg2)}
    elsif @type == :copy
      puts "Copying #{@arg1} to #{@arg2}" if @echo
      Dir.glob(@arg1).each {|f| FileUtils.cp_r(f, @arg2)}
    elsif @type == :remove
      puts "Removing #{@arg1}" if @echo
      Dir.glob(@arg1).each {|f| FileUtils.rm_rf(f)}
    elsif @type == :makedir
      puts "Making #{@arg1}" if @echo
      FileUtils.mkdir_p(@arg1)
    end
  end
  return true
end
startupStep() click to toggle source
# File lib/blocks/fileutil.rb, line 49
def startupStep
  return run()
end