Class: Git::Status

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/git/status.rb

Defined Under Namespace

Classes: StatusFile

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Status

Returns a new instance of Status



6
7
8
9
# File 'lib/git/status.rb', line 6

def initialize(base)
  @base = base
  construct_status
end

Instance Method Details

#[](file) ⇒ Object

enumerable method



49
50
51
# File 'lib/git/status.rb', line 49

def [](file)
  @files[file]
end

#addedObject



15
16
17
# File 'lib/git/status.rb', line 15

def added
  @files.select { |k, f| f.type == 'A' }
end

#changedObject



11
12
13
# File 'lib/git/status.rb', line 11

def changed
  @files.select { |k, f| f.type == 'M' }
end

#deletedObject



19
20
21
# File 'lib/git/status.rb', line 19

def deleted
  @files.select { |k, f| f.type == 'D' }
end

#each(&block) ⇒ Object



53
54
55
# File 'lib/git/status.rb', line 53

def each(&block)
  @files.values.each(&block)
end

#prettyObject



27
28
29
30
31
32
33
34
# File 'lib/git/status.rb', line 27

def pretty
  out = ''
  self.each do |file|
    out << pretty_file(file)
  end
  out << "\n"
  out
end

#pretty_file(file) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/git/status.rb', line 36

def pretty_file(file)
  <<FILE
#{file.path}
\tsha(r) #{file.sha_repo.to_s} #{file.mode_repo.to_s}
\tsha(i) #{file.sha_index.to_s} #{file.mode_index.to_s}
\ttype   #{file.type.to_s}
\tstage  #{file.stage.to_s}
\tuntrac #{file.untracked.to_s}
FILE
end

#untrackedObject



23
24
25
# File 'lib/git/status.rb', line 23

def untracked
  @files.select { |k, f| f.untracked }
end