Class: Grit::Status

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

Defined Under Namespace

Classes: StatusFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Status

Returns a new instance of Status.



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

def initialize(base)
  @base = base
  construct_status
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

Instance Method Details

#[](file) ⇒ Object

enumerable method



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

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

#addedObject



20
21
22
# File 'lib/grit/status.rb', line 20

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

#changedObject



16
17
18
# File 'lib/grit/status.rb', line 16

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

#deletedObject



24
25
26
# File 'lib/grit/status.rb', line 24

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

#eachObject



53
54
55
56
57
# File 'lib/grit/status.rb', line 53

def each
  @files.each do |k, file|
    yield file
  end
end

#prettyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/grit/status.rb', line 32

def pretty
  out = ''
  self.each do |file|
    out << file.path
    out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s
    out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s
    out << "\n\ttype   " + file.type.to_s
    out << "\n\tstage  " + file.stage.to_s
    out << "\n\tuntrac " + file.untracked.to_s
    out << "\n"
  end
  out << "\n"
  out
end

#untrackedObject



28
29
30
# File 'lib/grit/status.rb', line 28

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