Class: DoubleEntry::Validation::LineCheck
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DoubleEntry::Validation::LineCheck
- Defined in:
- lib/double_entry/validation/line_check.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.last_line_id_checked ⇒ Object
8 9 10 |
# File 'lib/double_entry/validation/line_check.rb', line 8 def self.last_line_id_checked order('created_at DESC').limit(1).pluck(:last_line_id).first || 0 end |
.perform!(fixer: nil) ⇒ Object
12 13 14 |
# File 'lib/double_entry/validation/line_check.rb', line 12 def self.perform!(fixer: nil) new.perform(fixer: fixer) end |
Instance Method Details
#perform(fixer: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/double_entry/validation/line_check.rb', line 16 def perform(fixer: nil) log = '' current_line_id = nil active_accounts = Set.new incorrect_accounts = Set.new new_lines_since_last_run.find_each do |line| incorrect_accounts << line.account unless running_balance_correct?(line, log) active_accounts << line.account current_line_id = line.id end active_accounts.each do |account| incorrect_accounts << account unless cached_balance_correct?(account, log) end incorrect_accounts.each(&fixer.method(:recalculate_account)) if fixer unless active_accounts.empty? LineCheck.create!( errors_found: incorrect_accounts.any?, last_line_id: current_line_id, log: log, ) end end |