Class: Move

Inherits:
Item
  • Object
show all
Defined in:
app/models/move.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

#before_validation

Class Method Details

.find_conflict(item) ⇒ Object

validations



9
10
11
12
13
14
15
16
# File 'app/models/move.rb', line 9

def self.find_conflict(item)
  Move.all(:conditions => {
    :date => item.date,
    :account_id_from => item.,
    :account_id_to => item.,
    :position => item.position,
  }).reject{|x| x.id == item.id}.first
end

Instance Method Details

#find_positionObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/move.rb', line 33

def find_position
  klass = self.class
  items = klass.all(conditions: {
    date: self.date,
    account_id_from: self.,
    account_id_to: self.,
  })

  n = 0
  loop do
    if items.none?{|item| item.position == n}
      $stderr.puts "[find_position] #{n}"
      return n
    end
    n += 1
  end
end

#validateObject



18
19
20
21
22
23
# File 'app/models/move.rb', line 18

def validate
  if  && ( == )
    errors.add("account_id_from", "from and to must not be same")
  end
  super
end