• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sleede / fab-manager / #106

pending completion
#106

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 6.0.0

704 of 704 new or added lines in 168 files covered. (100.0%)

7919 of 13474 relevant lines covered (58.77%)

15.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.66
/lib/tasks/fablab/chain.rake
1
# frozen_string_literal: true
2

3
namespace :fablab do
1✔
4
  namespace :chain do
1✔
5
    desc 'assign all footprints to existing records'
1✔
6
    task :all, [:force] => :environment do |_task, args|
1✔
7
      if Invoice.where.not(footprint: nil).count.positive? && args.force != 'force'
×
8
        print 'All footprints will be regenerated. Are you sure? (y/n) '
×
9
        confirm = $stdin.gets.chomp
×
10
        next unless confirm == 'y'
×
11
      end
12
      chain_invoices
×
13
      chain_invoice_items
×
14
      chain_history_values
×
15
      chain_payment_schedules
×
16
      chain_payment_schedules_items
×
17
      chain_payment_schedules_objects if ActiveRecord::Base.connection.table_exists? PaymentScheduleObject.arel_table
×
18
    end
19

20
    desc 'assign all footprints to existing Invoice records'
1✔
21
    task invoices: :environment do
1✔
22
      if Invoice.where.not(footprint: nil).count.positive?
×
23
        print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
×
24
        confirm = $stdin.gets.chomp
×
25
        next unless confirm == 'y'
×
26
      end
27
      chain_invoices
×
28
    end
29

30
    def chain_invoices
1✔
31
      if AccountingPeriod.count.positive?
×
32
        last_period = AccountingPeriod.order(start_at: :desc).first
×
33
        puts "Regenerating from #{last_period.end_at}..."
×
34
        Invoice.where('created_at > ?', last_period.end_at).order(:id).find_each(&:chain_record)
×
35
      else
36
        puts '(Re)generating all footprint...'
×
37
        Invoice.order(:id).find_each(&:chain_record)
×
38
      end
39
    end
40

41
    desc 'assign all footprints to existing InvoiceItem records'
1✔
42
    task invoices_items: :environment do
1✔
43
      if InvoiceItem.where.not(footprint: nil).count.positive?
×
44
        print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
×
45
        confirm = $stdin.gets.chomp
×
46
        next unless confirm == 'y'
×
47
      end
48
      chain_invoice_items
×
49
    end
50

51
    def chain_invoice_items
1✔
52
      if AccountingPeriod.count.positive?
×
53
        last_period = AccountingPeriod.order(start_at: :desc).first
×
54
        puts "Regenerating from #{last_period.end_at}..."
×
55
        InvoiceItem.where('created_at > ?', last_period.end_at).order(:id).find_each(&:chain_record)
×
56
      else
57
        puts '(Re)generating all footprint...'
×
58
        InvoiceItem.order(:id).find_each(&:chain_record)
×
59
      end
60
    end
61

62
    desc 'assign all footprints to existing HistoryValue records'
1✔
63
    task history_values: :environment do
1✔
64
      if HistoryValue.where.not(footprint: nil).count.positive?
×
65
        print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
×
66
        confirm = $stdin.gets.chomp
×
67
        next unless confirm == 'y'
×
68
      end
69
      chain_history_values
×
70
    end
71

72
    def chain_history_values
1✔
73
      HistoryValue.order(:created_at).find_each(&:chain_record)
×
74
    end
75

76
    desc 'assign all footprints to existing PaymentSchedule records'
1✔
77
    task payment_schedule: :environment do
1✔
78
      if PaymentSchedule.where.not(footprint: nil).count.positive?
×
79
        print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
×
80
        confirm = $stdin.gets.chomp
×
81
        next unless confirm == 'y'
×
82
      end
83
      chain_payment_schedules
×
84
    end
85

86
    def chain_payment_schedules
1✔
87
      if AccountingPeriod.count.positive?
×
88
        last_period = AccountingPeriod.order(start_at: :desc).first
×
89
        puts "Regenerating from #{last_period.end_at}..."
×
90
        PaymentSchedule.where('created_at > ?', last_period.end_at).order(:id).find_each(&:chain_record)
×
91
      else
92
        puts '(Re)generating all footprint...'
×
93
        PaymentSchedule.order(:id).find_each(&:chain_record)
×
94
      end
95
    end
96

97
    desc 'assign all footprints to existing PaymentScheduleItem records'
1✔
98
    task payment_schedule_item: :environment do
1✔
99
      if PaymentScheduleItem.where.not(footprint: nil).count.positive?
×
100
        print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
×
101
        confirm = $stdin.gets.chomp
×
102
        next unless confirm == 'y'
×
103
      end
104
      chain_payment_schedules_items
×
105
    end
106

107
    def chain_payment_schedules_items
1✔
108
      if AccountingPeriod.count.positive?
×
109
        last_period = AccountingPeriod.order(start_at: :desc).first
×
110
        puts "Regenerating from #{last_period.end_at}..."
×
111
        PaymentScheduleItem.where('created_at > ?', last_period.end_at).order(:id).find_each(&:chain_record)
×
112
      else
113
        puts '(Re)generating all footprint...'
×
114
        PaymentScheduleItem.order(:id).find_each(&:chain_record)
×
115
      end
116
    end
117

118
    desc 'assign all footprints to existing PaymentScheduleObject records'
1✔
119
    task payment_schedule_object: :environment do
1✔
120
      if PaymentScheduleObject.where.not(footprint: nil).count.positive?
×
121
        print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
×
122
        confirm = $stdin.gets.chomp
×
123
        next unless confirm == 'y'
×
124
      end
125
      chain_payment_schedules_objects
×
126
    end
127

128
    def chain_payment_schedules_objects
1✔
129
      if AccountingPeriod.count.positive?
×
130
        last_period = AccountingPeriod.order(start_at: :desc).first
×
131
        puts "Regenerating from #{last_period.end_at}..."
×
132
        PaymentScheduleObject.where('created_at > ?', last_period.end_at).order(:id).find_each(&:chain_record)
×
133
      else
134
        puts '(Re)generating all footprint...'
×
135
        PaymentScheduleObject.order(:id).find_each(&:chain_record)
×
136
      end
137
    end
138
  end
139
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc