Class: ProspectusRepotimer::Timer

Inherits:
Module
  • Object
show all
Defined in:
lib/prospectus_repotimer.rb

Overview

Helper for automatically adding timer check

Instance Method Summary collapse

Constructor Details

#initialize(days_ago) ⇒ Timer

Returns a new instance of Timer.



7
8
9
# File 'lib/prospectus_repotimer.rb', line 7

def initialize(days_ago)
  @days_ago = days_ago || raise('No age specified')
end

Instance Method Details

#days_ago_arrayObject



43
44
45
# File 'lib/prospectus_repotimer.rb', line 43

def days_ago_array
  @days_ago.downto(0).to_a
end

#extended(other) ⇒ Object

rubocop:disable Metrics/MethodLength



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/prospectus_repotimer.rb', line 11

def extended(other) # rubocop:disable Metrics/MethodLength
  actual_val, expected_val = parse_status

  other.deps do
    item do
      name 'timer'

      expected do
        static
        set expected_val
      end

      actual do
        static
        set actual_val
      end
    end
  end
end

#last_commitObject



39
40
41
# File 'lib/prospectus_repotimer.rb', line 39

def last_commit
  @last_commit ||= Date.parse(`git show --format=%cI -s`)
end

#last_commit_days_agoObject



35
36
37
# File 'lib/prospectus_repotimer.rb', line 35

def last_commit_days_ago
  @last_commit_days_ago ||= (Date.today - last_commit).to_i
end

#parse_statusObject



31
32
33
# File 'lib/prospectus_repotimer.rb', line 31

def parse_status
  [last_commit_days_ago, days_ago_array]
end