Module: ServerPush
- Included in:
- Todo
- Defined in:
- lib/server_skeleton/server_push.rb
Overview
included into ActiveRecord models
Instance Method Summary collapse
- #destroy(*args) ⇒ Object
-
#publish_to ⇒ Object
Can be overridden in model to limit who gets updates Returns a list of sockets (by default all of them).
- #save(*args) ⇒ Object
- #update(*args) ⇒ Object
Instance Method Details
#destroy(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/server_skeleton/server_push.rb', line 39 def destroy(*args) result = super(*args) unless persisted? publish_to.each do |socket| socket.send({ action: "destroy_record", type: self.class.to_s.underscore, record: public_attributes }.to_json) end end result end |
#publish_to ⇒ Object
Can be overridden in model to limit who gets updates Returns a list of sockets (by default all of them)
6 7 8 |
# File 'lib/server_skeleton/server_push.rb', line 6 def publish_to Sockets.values.map(&:to_a).flatten end |
#save(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/server_skeleton/server_push.rb', line 10 def save(*args) should_push = valid? && !persisted? result = super(*args) if should_push publish_to.each do |socket| socket.send({ action: "add_record", type: self.class.to_s.underscore, record: public_attributes }.to_json) end end result end |
#update(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/server_skeleton/server_push.rb', line 25 def update(*args) result = super(*args) if result publish_to.each do |socket| socket.send({ action: "update_record", type: self.class.to_s.underscore, record: public_attributes }.to_json) end end result end |