Skip to content

Instantly share code, notes, and snippets.

@michaelklishin
Created October 20, 2008 02:06
Show Gist options
  • Save michaelklishin/17994 to your computer and use it in GitHub Desktop.
Save michaelklishin/17994 to your computer and use it in GitHub Desktop.
New entry posted to the journal:
= self.params[:entry].body
def index(entry = {})
@entry = Entry.new(entry)
@entries = Entry.all(:order => [:created_at.desc])
JournalMessenger.dispatch(:index, self)
display @entries
end
def create(entry)
@entry = Entry.new(entry)
if @entry.save
run_later do
JournalMessenger.dispatch(:create, self, :entry => @entry)
end
redirect url(:entries)
else
@entries = Entry.all
render :index
end
end
Merb::BootLoader.before_app_loads do
Merb::MessagingController.message_transport :local, :growl, {
:host => "localhost",
:application => "ruby-growl",
:notifications => ["journal notification", "presence notification"]
}
Merb::MessagingController.message_transport :remote, :xmpp4r, {
:jid => "merbpack@stormblast",
:password => "merbpack"
}
end
Merb::BootLoader.after_app_loads do
im = Merb::MessagingController.message_transport :local
im.deliver({
:title => "MerbPack presence",
:body => "MerbPack agent is back online",
:notification => "presence notification"
})
end
Merb::BootLoader.before_master_shutdown do
Merb.logger.info "Disconnecting XMPP notification agent..."
im = Merb::MessagingController.message_transport :local
im.deliver({
:title => "MerbPack presence",
:body => "MerbPack agent is about to shut down",
:notification => "presence notification"
})
im.disconnect
end
Merb::BootLoader.before_worker_shutdown do
Merb.logger.info "Shutting down worker..."
Merb::MessagingController.message_transport(:remote).disconnect
end
class JournalMessenger < Merb::MessagingController
delivery_options :local,
:notification => "journal notification",
:title => "New MerbPack event"
delivery_options :remote,
:title => "Journal event",
:to => ["antares@stormblast"],
:message_type => :chat
def index(options)
body = render(:index)
deliver :remote, :body => body
deliver :local, :body => body
end
def create(options)
self.deliver :remote, :body => render(:create)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment