Class: Ballantine::Commit

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash:, repo:) ⇒ Commit

Returns a new instance of Commit.

Parameters:



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

def initialize(hash:, repo:)
  @hash = hash[...7]
  @repo = repo
end

Instance Attribute Details

#authorObject (readonly)

associations



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

def author
  @author
end

#hashObject (readonly)

attributes



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

def hash
  @hash
end

#long_hashObject (readonly)

attributes



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

def long_hash
  @long_hash
end

#repoObject (readonly)

associations



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

def repo
  @repo
end

#subjectObject (readonly)

attributes



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

def subject
  @subject
end

Class Method Details

.find(hash:, repo:) ⇒ Commit, NilClass

Parameters:

Returns:



12
13
14
15
# File 'lib/ballantine/commit.rb', line 12

def find(hash:, repo:)
  @_collections = {} unless defined?(@_collections)
  @_collections["#{hash[...7]}-#{repo.name}"]
end

.find_or_create_by(hash:, repo:) ⇒ Commit

Parameters:

Returns:



20
21
22
# File 'lib/ballantine/commit.rb', line 20

def find_or_create_by(hash:, repo:)
  find(hash:, repo:) || @_collections["#{hash[...7]}-#{repo.name}"] = new(hash:, repo:)
end

Instance Method Details

#slack_messageString

Returns:



42
43
44
# File 'lib/ballantine/commit.rb', line 42

def slack_message
  "\`<#{url}|#{hash}>\` #{subject} - #{author.name}"
end

#update(**kwargs) ⇒ Commit

Returns:



33
34
35
36
37
# File 'lib/ballantine/commit.rb', line 33

def update(**kwargs)
  # TODO: validate keys and values
  kwargs.each { |key, value| instance_variable_set("@#{key}", value) }
  self
end

#urlObject



39
# File 'lib/ballantine/commit.rb', line 39

def url; @url ||= "#{repo.url}/commit/#{long_hash}" end