Class: Bake::Blocks::FileUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/blocks/fileutil.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, type, projectDir) ⇒ FileUtil

Returns a new instance of FileUtil.



8
9
10
11
12
13
14
# 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")
end

Instance Method Details

#cleanObject



54
55
56
57
# File 'lib/blocks/fileutil.rb', line 54

def clean
  # nothing to do here
  return true
end

#cleanStepObject



50
51
52
# File 'lib/blocks/fileutil.rb', line 50

def cleanStep
  return run()
end

#executeObject



38
39
40
# File 'lib/blocks/fileutil.rb', line 38

def execute
  return run()
end

#exitStepObject



46
47
48
# File 'lib/blocks/fileutil.rb', line 46

def exitStep
  return run()
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/blocks/fileutil.rb', line 16

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
      FileUtils.mv(@arg1, @arg2)
    elsif @type == :copy
      puts "Copying #{@arg1} to #{@arg2}" if @echo
      FileUtils.cp_r(@arg1, @arg2)
    elsif @type == :remove
      puts "Removing #{@arg1}" if @echo
      FileUtils.rm_rf(@arg1)
    elsif @type == :makedir
      puts "Making #{@arg1}" if @echo
      FileUtils.mkdir_p(@arg1)
    end
  end
  return true
end

#startupStepObject



42
43
44
# File 'lib/blocks/fileutil.rb', line 42

def startupStep
  return run()
end