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.0"

Instance Method Summary collapse

Instance Method Details

#extract_dir_nameObject



30
31
32
# File 'lib/git_explorer.rb', line 30

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

#extract_light_status(status_output) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/git_explorer.rb', line 21

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

#extract_path(line, root_dir) ⇒ Object



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

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
# 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 = :up_to_date unless status_output[/not staged/]
    status = :not_staged if status_output[/not staged/]
    files = status_output.scan(/modified: \s*(.*)$/).flatten
    GitStatus.new(status, project_name, branch, files)
  }
end

#git_repository?(path) ⇒ Boolean



39
40
41
42
43
44
# File 'lib/git_explorer.rb', line 39

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



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

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