Class: FayePluginObserver
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- FayePluginObserver
- Defined in:
- lib/faye-plugin/observers/faye_plugin_observer.rb
Instance Method Summary collapse
- #after_update(model) ⇒ Object
- #before_update(model) ⇒ Object
- #broadcast_message(channel, data) ⇒ Object
Instance Method Details
#after_update(model) ⇒ Object
22 23 24 |
# File 'lib/faye-plugin/observers/faye_plugin_observer.rb', line 22 def after_update(model) @client_changes.call end |
#before_update(model) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/faye-plugin/observers/faye_plugin_observer.rb', line 10 def before_update(model) if model.changed? @client_changes = lambda do model.changes.each do |key, value| ("/listener", "$(\"##{model.class.name.downcase}_#{model.id}_#{key}\").html(\"#{value[1]}\")") end end else @client_changes = lambda {} end end |
#broadcast_message(channel, data) ⇒ Object
4 5 6 7 8 |
# File 'lib/faye-plugin/observers/faye_plugin_observer.rb', line 4 def (channel, data) = {:channel => channel, :data => data, :ext => {:auth_token => FAYE_TOKEN}} uri = URI.parse("http://#{Rails.configuration.faye_host}:#{Rails.configuration.faye_port}/faye") Net::HTTP.post_form(uri, :message => .to_json) end |