Class: Capillary::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/capillary/commit.rb

Constant Summary collapse

LOG_SEPARATOR =
"ยง"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommit

Returns a new instance of Commit.



28
29
30
# File 'lib/capillary/commit.rb', line 28

def initialize
  @refs = RefCollection.new
end

Instance Attribute Details

#committed_atObject

Returns the value of attribute committed_at.



24
25
26
# File 'lib/capillary/commit.rb', line 24

def committed_at
  @committed_at
end

#committer_emailObject

Returns the value of attribute committer_email.



24
25
26
# File 'lib/capillary/commit.rb', line 24

def committer_email
  @committer_email
end

#idObject

Returns the value of attribute id.



24
25
26
# File 'lib/capillary/commit.rb', line 24

def id
  @id
end

#messageObject

Returns the value of attribute message.



24
25
26
# File 'lib/capillary/commit.rb', line 24

def message
  @message
end

#parent_idsObject

Returns the value of attribute parent_ids.



24
25
26
# File 'lib/capillary/commit.rb', line 24

def parent_ids
  @parent_ids
end

#refsObject (readonly)

Returns the value of attribute refs.



25
26
27
# File 'lib/capillary/commit.rb', line 25

def refs
  @refs
end

#seq_idObject

Returns the value of attribute seq_id.



24
25
26
# File 'lib/capillary/commit.rb', line 24

def seq_id
  @seq_id
end

Class Method Details

.parse(git_line) ⇒ Object

Creates an instance from Git output



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/capillary/commit.rb', line 33

def self.parse(git_line)
  git_line = git_line.gsub(/^[^a-f0-9]+/, "")
  return nil if git_line == ""

  parts = git_line.split(LOG_SEPARATOR)
  result = new
  result.id = parts[0]
  result.parent_ids = parts[1].split(" ")
  result.committed_at = Time.parse(parts[2])
  result.committer_email = parts[3]
  result.refs.parse(parts[4])
  result.message = parts[5]
  result
end

Instance Method Details

#to_hashObject



48
49
50
51
52
53
54
55
# File 'lib/capillary/commit.rb', line 48

def to_hash
  { "id" => id,
    "parent_ids" => parent_ids,
    "committed_at" => committed_at,
    "committer_email" => committer_email,
    "refs" => refs.to_hash,
    "message" => message }
end

#to_jsonObject



57
58
59
60
61
62
63
64
65
# File 'lib/capillary/commit.rb', line 57

def to_json
  JSON.unparse({ "id" => id,
                 "parentIds" => parent_ids,
                 "committedAt" => committed_at,
                 "committerEmail" => committer_email,
                 "refs" => refs.to_hash,
                 "message" => message,
                 "seqId" => seq_id})
end