Class: Esvien::Commit

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/esvien/commit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, repo) ⇒ Commit

Returns a new instance of Commit.



10
11
12
13
# File 'lib/esvien/commit.rb', line 10

def initialize(id, repo)
  @id = id
  @repo = repo
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



5
6
7
# File 'lib/esvien/commit.rb', line 5

def author
  @author
end

#dateObject

Returns the value of attribute date.



6
7
8
# File 'lib/esvien/commit.rb', line 6

def date
  @date
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/esvien/commit.rb', line 3

def id
  @id
end

#repoObject (readonly)

Returns the value of attribute repo.



4
5
6
# File 'lib/esvien/commit.rb', line 4

def repo
  @repo
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/esvien/commit.rb', line 15

def <=>(other)
  if other.is_a?(Commit)
    if self.repo == other.repo
      return id <=> other.id
    else
      raise Esvien::RepositoryMismatch
    end
  else
    raise ArgumentError, "Cannot compare #{self.class} with #{other.class}"
  end
end

#pretty_print(pp) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/esvien/commit.rb', line 27

def pretty_print(pp)
  pp.group(1, %{#<#{self.class}}, %{>}) do
    pp.breakable
    pp.seplist(%w[id repo], lambda { pp.comma_breakable }) do |attr|
      pp.text(attr)
      pp.text("=")
      pp.pp(send(attr))
    end
  end
end