Class: Item

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/item.rb

Direct Known Subclasses

Move, SimpleItem

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_conflict(item) ⇒ Object



17
18
19
# File 'app/models/item.rb', line 17

def self.find_conflict(item)
  item.type.constantize.find_conflict(item)
end

Instance Method Details

#before_validationObject

validations



6
7
8
9
10
# File 'app/models/item.rb', line 6

def before_validation
  self.title = "" if self.title.nil?
  self.amount = 0 if self.amount.blank?
  self.position = find_position if self.position.nil?
end

#validateObject



21
22
23
24
25
26
# File 'app/models/item.rb', line 21

def validate
  # validate index of day
  if same = self.class.find_conflict(self)
    errors.add("position", "position #{position} conflicts with #{same.title} (#{same.amount}, #{same.date})")
  end
end