Class: Git::Lint::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/git/lint/collector.rb

Overview

Collects and categorizes, by severity, all issues (if any).

Instance Method Summary collapse

Constructor Details

#initialize(model: Models::Total) ⇒ Collector

Returns a new instance of Collector.



7
8
9
10
# File 'lib/git/lint/collector.rb', line 7

def initialize model: Models::Total
  @model = model
  @collection = Hash.new { |default, missing_id| default[missing_id] = [] }
end

Instance Method Details

#add(analyzer) ⇒ Object



12
13
14
15
# File 'lib/git/lint/collector.rb', line 12

def add analyzer
  collection[analyzer.commit] << analyzer
  analyzer
end

#clearObject



30
# File 'lib/git/lint/collector.rb', line 30

def clear = collection.clear && self

#empty?Boolean

Returns:

  • (Boolean)


32
# File 'lib/git/lint/collector.rb', line 32

def empty? = collection.empty?

#retrieve(id) ⇒ Object



28
# File 'lib/git/lint/collector.rb', line 28

def retrieve(id) = collection[id]

#to_hObject



34
# File 'lib/git/lint/collector.rb', line 34

def to_h = collection

#totalObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/git/lint/collector.rb', line 17

def total
  values = collection.values.flatten

  model[
    items: collection.keys.compact.size,
    issues: values.count(&:invalid?),
    warnings: values.count(&:warning?),
    errors: values.count(&:error?)
  ]
end