Module: GitExplorer

Included in:
Explorer
Defined in:
lib/git_explorer.rb,
lib/gitexplorer/version.rb

Defined Under Namespace

Classes: Explorer, GitStatus

Constant Summary collapse

VERSION =
"0.2.2"

Instance Method Summary collapse

Instance Method Details

#extract_dir_nameObject



34
35
36
# File 'lib/git_explorer.rb', line 34

def extract_dir_name
  -> (dot_git_file_path) { dot_git_file_path.gsub(/\.git$/,'') }
end

#extract_light_status(status_output) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/git_explorer.rb', line 23

def extract_light_status(status_output)
  project_name = status_output[/^(?<project_name>.*)$/, "project_name"]
  branch = status_output[/On branch\s(?<branch>.*)/, "branch"]
  status = []
  status << :up_to_date if status_output[/up-to-date/]
  status << :not_staged if status_output[/not staged/]
  status << :to_be_committed if status_output[/to be committed/]
  files = status_output.scan(/modified: \s*(.*)$/).flatten
  GitStatus.new(status, project_name, branch, files)
end

#extract_path(line, root_dir) ⇒ Object



38
39
40
41
# File 'lib/git_explorer.rb', line 38

def extract_path(line, root_dir)
  parsed_path = line[/.*\s(?<path>.*)$/, 'path']
  root_dir + parsed_path
end

#extract_statusObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/git_explorer.rb', line 10

def extract_status
  -> (status_output) {
    project_name = status_output[/^(?<project_name>.*)$/, "project_name"]
    branch = status_output[/On branch\s(?<branch>.*)/, "branch"]
    status = []
    status << :up_to_date if status_output[/up-to-date/]
    status << :not_staged if status_output[/not staged/]
    status << :to_be_committed if status_output[/to be committed/]
    files = status_output.scan(/modified: \s*(.*)$/).flatten
    GitStatus.new(status, project_name, branch, files)
  }
end

#git_repository?(path) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/git_explorer.rb', line 43

def git_repository?(path)
  return nil if path.nil?
  is_directory = File.directory?(path)
  is_repository = run("find #{path} -maxdepth 1 -type d -name .git", config={:capture=>true, :verbose=>false}) if is_directory
  is_directory and !is_repository.empty?
end

#git_status(path) ⇒ Object



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

def git_status(path)
  run("basename `git -C #{path} rev-parse --show-toplevel`; git -C #{path} status", config={:capture=>true, :verbose=>false})
end

#translate_color(statuses) ⇒ Object



65
66
67
68
69
70
# File 'lib/git_explorer.rb', line 65

def translate_color(statuses)
  return :green if statuses == [:up_to_date]
  return :red if statuses == [:conflict]

  :cyan
end

#translate_status(statuses) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/git_explorer.rb', line 54

def translate_status(statuses)
  possible_status = {
      to_be_committed: '',
      up_to_date: '',
      not_staged: '',
      conflict: ''
  }

  statuses.inject('') {|string, status| string = string + possible_status[status].to_s}
end