Class: CoverRage::Record

Inherits:
Data
  • Object
show all
Defined in:
lib/cover_rage/record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#execution_countObject (readonly)

Returns the value of attribute execution_count

Returns:

  • (Object)

    the current value of execution_count



4
5
6
# File 'lib/cover_rage/record.rb', line 4

def execution_count
  @execution_count
end

#last_executed_atObject (readonly)

Returns the value of attribute last_executed_at

Returns:

  • (Object)

    the current value of last_executed_at



4
5
6
# File 'lib/cover_rage/record.rb', line 4

def last_executed_at
  @last_executed_at
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/cover_rage/record.rb', line 4

def path
  @path
end

#revisionObject (readonly)

Returns the value of attribute revision

Returns:

  • (Object)

    the current value of revision



4
5
6
# File 'lib/cover_rage/record.rb', line 4

def revision
  @revision
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



4
5
6
# File 'lib/cover_rage/record.rb', line 4

def source
  @source
end

Class Method Details

.merge(existing_records, current_records) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cover_rage/record.rb', line 5

def self.merge(existing_records, current_records)
  records_to_save = []
  current_records.each do |current_record|
    existing_record = existing_records.find { _1.path == current_record.path }
    records_to_save <<
      if existing_record.nil? || current_record.revision != existing_record.revision
        current_record
      else
        existing_record + current_record
      end
  end
  records_to_save
end

Instance Method Details

#+(other) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cover_rage/record.rb', line 19

def +(other)
  with(
    execution_count: execution_count.map.with_index do |item, index|
      other_item = other.execution_count[index]
      if item.nil? && other_item.nil? then nil
      elsif item.nil? || other_item.nil? then other_item
      else item + other_item
      end
    end,
    last_executed_at: last_executed_at.map.with_index do |item, index|
      other_item = other.last_executed_at[index]
      if item.nil? && other_item.nil? then nil
      elsif item.nil? || other_item.nil? then other_item
      else [item, other_item].max
      end
    end
  )
end