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.



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

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



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

def message
  @message.gsub(/[^A-Za-z0-9\s\'\n\.,\/]/,"")
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.



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

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



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

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



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

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



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

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