Class: SeapigSlaveObject

Inherits:
SeapigObject show all
Defined in:
lib/seapig-client-ruby/client.rb

Direct Known Subclasses

SeapigWildcardSlaveObject

Instance Attribute Summary collapse

Attributes inherited from SeapigObject

#destroyed, #id, #initialized, #version

Instance Method Summary collapse

Methods inherited from SeapigObject

#destroy, #matches, #ondestroy, #onstatuschange, #sanitized, #unlink

Constructor Details

#initialize(client, id, options) ⇒ SeapigSlaveObject

Returns a new instance of SeapigSlaveObject.



249
250
251
252
253
254
# File 'lib/seapig-client-ruby/client.rb', line 249

def initialize(client, id, options)
	super(client, id, options)
	@version = (options[:version] or 0)
	@valid = false
	@received_at = nil
end

Instance Attribute Details

#received_atObject (readonly)

Returns the value of attribute received_at.



246
247
248
# File 'lib/seapig-client-ruby/client.rb', line 246

def received_at
  @received_at
end

#validObject (readonly)

Returns the value of attribute valid.



246
247
248
# File 'lib/seapig-client-ruby/client.rb', line 246

def valid
  @valid
end

Instance Method Details

#invalidateObject



291
292
293
294
# File 'lib/seapig-client-ruby/client.rb', line 291

def invalidate
	@valid = false
	@onstatuschange_proc.call(self) if @onstatuschange_proc
end

#onchange(&block) ⇒ Object



257
258
259
260
# File 'lib/seapig-client-ruby/client.rb', line 257

def onchange(&block)
	@onchange_proc = block
	self
end

#patch(message) ⇒ Object

—– for SeapigClient



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/seapig-client-ruby/client.rb', line 264

def patch(message)
	@received_at = Time.new
	old_self = JSON.dump(self)
	if (not message['version-old']) or (message['version-old'] == 0) or message.has_key?('value')
		self.clear
	elsif not @version == message['version-old']
		raise "Seapig lost some updates, this should never happen: "+[self, @version, message].inspect
	end
	if message['value']
		self.merge!(message['value'])
	else
		Hana::Patch.new(message['patch']).apply(self)
	end
	@version = message['version-new']
	@valid = true
	@initialized = true
	@onstatuschange_proc.call(self) if @onstatuschange_proc
	@onchange_proc.call(self) if @onchange_proc and old_self != JSON.dump(self)
end

#validateObject



285
286
287
288
# File 'lib/seapig-client-ruby/client.rb', line 285

def validate
	@valid = @initialized
	@onstatuschange_proc.call(self) if @onstatuschange_proc
end