Class: Hootenanny::PublishNotification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hootenanny::PublishNotification
- Defined in:
- app/models/hootenanny/publish_notification.rb
Class Method Summary collapse
- .each_unprocessed ⇒ Object
- .expired ⇒ Object
-
.for(topic) ⇒ Object
Private: Retrieves a set of notifications for a given set of topics.
-
.notify(topic) ⇒ Object
Private: Creates a notification for a given topic.
- .processed ⇒ Object
- .unprocessed ⇒ Object
Instance Method Summary collapse
Class Method Details
.each_unprocessed ⇒ Object
65 66 67 68 69 |
# File 'app/models/hootenanny/publish_notification.rb', line 65 def self.each_unprocessed unprocessed.find_each do |notification| yield notification end end |
.expired ⇒ Object
37 38 39 |
# File 'app/models/hootenanny/publish_notification.rb', line 37 def self.expired where(:state => 'expired') end |
.for(topic) ⇒ Object
Private: Retrieves a set of notifications for a given set of topics. If given one topic, only one notification should be returned since there can only be one notification for a given topic in the queue at any time.
topic - A String or an Array representing the Topic to look for.
Examples:
Hootenanny::PublishNotification.for('http://mytopic')
#=> <ActiveRecord::Relation>
Hootenanny::PublishNotification.for %w{http://mytopic
http://anothertopic}
#=> <ActiveRecord::Relation>
Returns an ActiveRecord::Relation
25 26 27 |
# File 'app/models/hootenanny/publish_notification.rb', line 25 def self.for(topic) where(:topic => topic) end |
.notify(topic) ⇒ Object
Private: Creates a notification for a given topic. If the notification for the topic exists, it touches it to reflect the new update time and returns it. It does not create a new notification.
topic - A String representing a URI of a topic which has been proposed to
have been updated.
Examples:
Hootenanny::PublishNotification.notify('http://example.com')
# => <Hootenanny::PublishNotification topic: 'http://example.com'>
Returns a Hootenanny::PublishNotification Raises a Hootenanny::URI::InvalidSchemeError if the topic URI are using
something other than HTTP or HTTPS
Raises a Hootenanny::URI::InvalidError if the URI can’t be parsed properly
59 60 61 62 63 |
# File 'app/models/hootenanny/publish_notification.rb', line 59 def self.notify(topic) topic = Hootenanny::URI.parse(topic).to_s find_or_initialize(topic).touch end |
.processed ⇒ Object
33 34 35 |
# File 'app/models/hootenanny/publish_notification.rb', line 33 def self.processed where(:state => 'processed') end |
.unprocessed ⇒ Object
29 30 31 |
# File 'app/models/hootenanny/publish_notification.rb', line 29 def self.unprocessed where(:state => 'unprocessed') end |
Instance Method Details
#expire ⇒ Object
75 76 77 |
# File 'app/models/hootenanny/publish_notification.rb', line 75 def expire self.update_attributes(:state => 'expired') end |
#process ⇒ Object
71 72 73 |
# File 'app/models/hootenanny/publish_notification.rb', line 71 def process self.update_attributes(:state => 'processed') end |
#processed? ⇒ Boolean
79 80 81 |
# File 'app/models/hootenanny/publish_notification.rb', line 79 def processed? self.state == 'processed' end |