Class: Onboard::Patch

Inherits:
Object
  • Object
show all
Defined in:
lib/onboard/patch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = '/tmp/onboard/patches') ⇒ Patch

Returns a new instance of Patch.


12
13
14
# File 'lib/onboard/patch.rb', line 12

def initialize(dir = '/tmp/onboard/patches')
  @dir = dir
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.


10
11
12
# File 'lib/onboard/patch.rb', line 10

def dir
  @dir
end

Instance Method Details

#cleanupObject


20
21
22
23
24
25
# File 'lib/onboard/patch.rb', line 20

def cleanup
  Dir.foreach(dir) do |item|
    file = "#{dir}/#{item}"
    FileUtils.rm_r file if File.zero?(file)
  end
end

#close(patch_file = '') ⇒ Object


33
34
35
36
# File 'lib/onboard/patch.rb', line 33

def close(patch_file = '')
  patch_file.close
  cleanup
end

#open(project) ⇒ Object


27
28
29
30
31
# File 'lib/onboard/patch.rb', line 27

def open(project)
  patch_dir
  patch_file = File.open("#{dir}/#{Time.now.to_i}_#{project}.patch", 'w')
  patch_file
end

#patch_dirObject


16
17
18
# File 'lib/onboard/patch.rb', line 16

def patch_dir
  FileUtils.mkdir_p(dir) unless File.directory?(dir)
end