Class: Obst::TouchedFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/obst/touched_files.rb

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ TouchedFiles

Returns a new instance of TouchedFiles.



5
6
7
8
9
10
11
12
13
14
# File 'lib/obst/touched_files.rb', line 5

def initialize(**opts)
  @path = opts[:C]

  @pathspec =
    if cfg = opts[:cfg]
      opts[:pathspec] ||= cfg.dig_any(['pathspec'], ['touched_files', 'pathspec'])
    end

  @buffer = ["# Touch files in periods\n"]
end

Instance Method Details

#last_3_months_without_last_4_weeksObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/obst/touched_files.rb', line 43

def last_3_months_without_last_4_weeks
  before = (Time.now - (60 * 60 * 24 * 28)).strftime('%FT23:59:59')

  @buffer << "- 1 month ago"

  GroupByDays.new(C: @path, before: before, days: 28, pathspec: @pathspec).take(2).each_with_index do |record, i|
    @buffer << "\t- #{record.time} is #{1+i}.month#{suffix_s(i)}.ago (#{record.file_changes.count})"
    list_files(record)
  end
end

#last_4_weeks_without_last_7_daysObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/obst/touched_files.rb', line 32

def last_4_weeks_without_last_7_days
  before = (Time.now - (60 * 60 * 24 * 7)).strftime('%FT23:59:59')

  @buffer << "- 1 week ago"

  GroupByDays.new(C: @path, before: before, days: 7, pathspec: @pathspec).take(3).each_with_index do |record, i|
    @buffer << "\t- #{record.time} is #{1+i}.week#{suffix_s(i)}.ago (#{record.file_changes.count})"
    list_files(record)
  end
end

#last_7_daysObject



23
24
25
26
27
28
29
30
# File 'lib/obst/touched_files.rb', line 23

def last_7_days
  @buffer << "- Last 7 days"

  GroupByDays.new(C: @path, pathspec: @pathspec).take(7).each do |record|
    @buffer << "\t- #{record.date_wday} (#{record.file_changes.count})"
    list_files(record)
  end
end

#list_files(record) ⇒ Object



54
55
56
57
58
# File 'lib/obst/touched_files.rb', line 54

def list_files(record)
  record.group_inlines do |line|
    @buffer << "\t\t- #{line}"
  end
end

#suffix_s(i) ⇒ Object



60
61
62
# File 'lib/obst/touched_files.rb', line 60

def suffix_s(i)
  i == 0 ? '' : 's'
end

#to_sObject



16
17
18
19
20
21
# File 'lib/obst/touched_files.rb', line 16

def to_s
  last_7_days
  last_4_weeks_without_last_7_days
  last_3_months_without_last_4_weeks
  @buffer.join("\n")
end