Class: Bake::Blocks::FileUtil
- Inherits:
-
Object
- Object
- Bake::Blocks::FileUtil
- Defined in:
- lib/blocks/fileutil.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #cleanStep ⇒ Object
- #execute ⇒ Object
- #exitStep ⇒ Object
-
#initialize(config, type, projectDir) ⇒ FileUtil
constructor
A new instance of FileUtil.
- #run ⇒ Object
- #startupStep ⇒ Object
Constructor Details
#initialize(config, type, projectDir) ⇒ FileUtil
Returns a new instance of FileUtil.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Method Details
#clean ⇒ Object
61 62 63 64 |
# File 'lib/blocks/fileutil.rb', line 61 def clean # nothing to do here return true end |
#cleanStep ⇒ Object
57 58 59 |
# File 'lib/blocks/fileutil.rb', line 57 def cleanStep return run() end |
#execute ⇒ Object
45 46 47 |
# File 'lib/blocks/fileutil.rb', line 45 def execute return run() end |
#exitStep ⇒ Object
53 54 55 |
# File 'lib/blocks/fileutil.rb', line 53 def exitStep return run() end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
49 50 51 |
# File 'lib/blocks/fileutil.rb', line 49 def startupStep return run() end |