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.



30
31
32
# File 'lib/capillary/commit.rb', line 30

def initialize
  @refs = RefCollection.new
end

Instance Attribute Details

#committed_atObject

Returns the value of attribute committed_at.



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

def committed_at
  @committed_at
end

#committer_emailObject

Returns the value of attribute committer_email.



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

def committer_email
  @committer_email
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#messageObject



69
70
71
# File 'lib/capillary/commit.rb', line 69

def message
  HTMLEntities.new.encode(@message)
end

#parent_idsObject

Returns the value of attribute parent_ids.



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

def parent_ids
  @parent_ids
end

#refsObject (readonly)

Returns the value of attribute refs.



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

def refs
  @refs
end

#seq_idObject

Returns the value of attribute seq_id.



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

def seq_id
  @seq_id
end

Class Method Details

.parse(git_line) ⇒ Object

Creates an instance from Git output



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

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

  parts = git_line.force_encoding('utf-8').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



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

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



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

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