Module: DDP::Server::RethinkDB::Helpers
- Included in:
- API
- Defined in:
- lib/ddp/server/rethinkdb/helpers.rb
Overview
Helper class that users can extend to implement an API that can be passed as the RPC API parameter to the RethinkDB DDP protocol
Instance Method Summary collapse
Instance Method Details
#wrap_changes(query, conn, on_update) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ddp/server/rethinkdb/helpers.rb', line 17 def wrap_changes(query, conn, on_update) query.changes().run(conn).each do |change| old_value = change['old_val'] new_value = change['new_val'] on_update.call(old_value, new_value) end conn.close end |
#wrap_query(query) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/ddp/server/rethinkdb/helpers.rb', line 8 def wrap_query(query) lambda do |&on_update| connection = new_connection results = query.run(connection) results.each { |r| on_update.call(nil, r) } wrap_changes(query, connection, on_update) end end |