lib/deepstream/record.rb in deepstream-1.0.4 vs lib/deepstream/record.rb in deepstream-1.0.5

- old
+ new

@@ -2,18 +2,21 @@ require_relative './constants' require_relative './helpers' module Deepstream class Record + attr_reader :data + def initialize(client, name) @client = client @name = name @data = {} @version = nil @is_reinitializing = false @data_cache = {} @client.send_message(TOPIC::RECORD, ACTION::CREATEORREAD, @name) + @ready_callback = nil end def reset_version @version = 0 end @@ -58,11 +61,19 @@ end rescue => e @client.on_exception(e) end + def when_ready(&block) + @ready_callback = block + end + def read(version, data) update(version, data) + if @ready_callback + @ready_callback.call(self) + @ready_callback = nil + end end def patch(version, path, value) @version = version.to_i set_path(@data, path, Helpers.to_type(value))