61c9f145f5aff0b2c37c73b009cf90d873cc7009
[rails.git] / app / models / map_bug.rb
1 class MapBug < ActiveRecord::Base
2   include GeoRecord
3
4   set_table_name 'map_bugs'
5
6   validates_presence_of :id, :on => :update
7   validates_uniqueness_of :id
8   validates_numericality_of :latitude, :only_integer => true
9   validates_numericality_of :longitude, :only_integer => true
10   validates_presence_of :date_created
11   validates_presence_of :last_changed
12   validates_inclusion_of :status, :in => [ "open", "closed", "hidden" ]
13
14
15   def self.create_bug(lat, lon, comment)
16         bug = MapBug.new(:lat => lat, :lon => lon);
17         raise OSM::APIBadUserInput.new("The node is outside this world") unless bug.in_world?
18         bug.text = comment
19         bug.date_created = Time.now.getutc
20         bug.last_changed = Time.now.getutc
21         bug.status = "open";
22         bug.save;
23         return bug;
24   end
25
26   def close_bug
27         self.status = "closed"
28         self.last_changed = Time.now.getutc
29         self.save;
30   end
31
32 end