Class: Appcast::Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Appcast::Message
- Defined in:
- lib/appcast/message.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_table ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/appcast/message.rb', line 7 def self.create_table connection.create_table :messages, :force => true do |t| t.column :name, :string t.column :content, :text t.column :locked_until, :datetime t.column :created_at, :datetime end connection.add_index :messages, :name end |
.get(path, limit, lock_seconds) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/appcast/message.rb', line 18 def self.get(path, limit, lock_seconds) now = Time.now.utc returning records = find(:all, :conditions => ["name LIKE ? AND (locked_until IS NULL OR locked_until < ?)", "#{path}%", now], :order => 'id', :limit => limit) do if lock_seconds and !records.empty? update_all(['locked_until = ?', now + lock_seconds.to_f], ['id IN (?)', records.collect(&:id)]) end end end |
.stats ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/appcast/message.rb', line 42 def self.stats s = connection.select_all("SELECT name, count(*) as count FROM messages GROUP by name").collect(&:values) s.unshift '--------------------------------------------' if recent = find(:first, :order => 'id ASC') s.unshift ['Most recent', recent.created_at.to_s(:short)] end s.unshift ['Total', count] s end |
Instance Method Details
#location ⇒ Object
32 33 34 |
# File 'lib/appcast/message.rb', line 32 def location "/messages/#{id}" end |
#to_xml(options = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/appcast/message.rb', line 36 def to_xml( = {}) [:only] = [:name, :content] [:methods] = [:location] super end |
#unlock ⇒ Object
28 29 30 |
# File 'lib/appcast/message.rb', line 28 def unlock update_attribute :locked_until, nil end |