Class: Cherrybase::FileUtil

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

Instance Method Summary collapse

Instance Method Details

#delete_temp_file(directory = File.expand_path('.')) ⇒ Object



25
26
27
# File 'lib/file_util.rb', line 25

def delete_temp_file(directory = File.expand_path('.'))
  File.delete(temp_file(directory))
end

#git_repo?(directory = File.expand_path('.')) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/file_util.rb', line 5

def git_repo?(directory = File.expand_path('.'))
  git_root_dir(directory) != nil
end

#git_root_dir(directory = File.expand_path('.')) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/file_util.rb', line 9

def git_root_dir(directory = File.expand_path('.'))
  current_directory = directory  
  while !File.exists?(File.join(current_directory, '.git'))
    current_directory = File.dirname(current_directory)
  end
  current_directory
end

#read_temp_file(directory = File.expand_path('.')) ⇒ Object



29
30
31
# File 'lib/file_util.rb', line 29

def read_temp_file(directory = File.expand_path('.'))
  YAML::load_file( temp_file(directory) )
end

#temp_file(directory = File.expand_path('.')) ⇒ Object



21
22
23
# File 'lib/file_util.rb', line 21

def temp_file(directory = File.expand_path('.'))
  File.join(File.join(git_root_dir(directory), '.git'), 'cherrybase')
end

#temp_file?(directory = File.expand_path('.')) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/file_util.rb', line 17

def temp_file?(directory = File.expand_path('.'))
  File.exist?(temp_file(directory))
end

#write_temp_file(starting_commit = nil, next_cherrypick = nil, commits = nil, directory = File.expand_path('.')) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/file_util.rb', line 33

def write_temp_file(starting_commit = nil, next_cherrypick = nil, commits = nil, directory = File.expand_path('.'))
  data = {
    "starting_commit" => starting_commit,
    "next_cherrypick" => next_cherrypick,
    "commits" => commits
  }
  filename = temp_file(directory)
  File.open(filename, "w") do |f|
      f.write(YAML::dump(data))
  end
end