Class: Space::Model::Repo::Git

Inherits:
Object
  • Object
show all
Includes:
Source
Defined in:
lib/space/model/repo/git.rb

Instance Attribute Summary collapse

Attributes included from Source

#results

Attributes included from Source::Watcher

#path

Instance Method Summary collapse

Methods included from Source

#commands, included, #refresh, #result, #update

Methods included from Events

events, flush, #notify, notify, sources, subscribe, subscriptions

Methods included from Source::Watcher

#watched_paths

Constructor Details

#initialize(repo) ⇒ Git

Returns a new instance of Git.



15
16
17
18
# File 'lib/space/model/repo/git.rb', line 15

def initialize(repo)
  @repo = repo
  super(repo.path)
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



13
14
15
# File 'lib/space/model/repo/git.rb', line 13

def repo
  @repo
end

Instance Method Details

#aheadObject



36
37
38
# File 'lib/space/model/repo/git.rb', line 36

def ahead
  result(:status) =~ /Your branch is ahead of .* by (\d+) commits?\./ ? $1.to_i : 0
end

#ahead?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/space/model/repo/git.rb', line 28

def ahead?
  ahead > 0
end

#branchObject



40
41
42
# File 'lib/space/model/repo/git.rb', line 40

def branch
  result(:branch) =~ /^\* (.+)/ && $1.strip
end

#clean?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/space/model/repo/git.rb', line 32

def clean?
  result(:status) =~ /nothing to commit (working directory clean)/
end

#commitObject



44
45
46
# File 'lib/space/model/repo/git.rb', line 44

def commit
  result(:commit) =~ /^commit (\S{7})/ && $1
end

#dirty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/space/model/repo/git.rb', line 24

def dirty?
  !clean?
end

#statusObject



20
21
22
# File 'lib/space/model/repo/git.rb', line 20

def status
  dirty? ? :dirty : (ahead? ? :ahead : :clean)
end