Class: DoubleEntry::Validation::LineCheck

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/double_entry/validation/line_check.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.perform!Object



9
10
11
# File 'lib/double_entry/validation/line_check.rb', line 9

def self.perform!
  new.perform
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/double_entry/validation/line_check.rb', line 13

def perform
  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. unless running_balance_correct?(line, log)
    active_accounts << line.
    current_line_id = line.id
  end

  active_accounts.each do ||
    incorrect_accounts <<       unless cached_balance_correct?()
  end

  incorrect_accounts.each { || () }

  unless active_accounts.empty?
    LineCheck.create!(
      :errors_found => incorrect_accounts.any?,
      :last_line_id => current_line_id,
      :log          => log,
    )
  end
end