Class: SeapigWildcardObject

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

Instance Attribute Summary

Attributes inherited from SeapigObject

#destroyed, #object_id, #parent, #received_at, #stall, #version, #version_requested

Instance Method Summary collapse

Methods inherited from SeapigObject

#matches?, #onchange, #onproduce, #reset, #sanitized, #send, #set, #upload, #valid?

Constructor Details

#initialize(*args) ⇒ SeapigWildcardObject

Returns a new instance of SeapigWildcardObject.



295
296
297
298
# File 'lib/seapig/client.rb', line 295

def initialize(*args)
	super(*args)
	@children = ObjectSpace::WeakMap.new
end

Instance Method Details

#destroy(message) ⇒ Object



308
309
310
311
312
313
# File 'lib/seapig/client.rb', line 308

def destroy(message)
	if destroyed = self.delete(message['id'])
		destroyed.destroyed = true
		@onchange_proc.call(destroyed) if @onchange_proc
	end
end

#patch(message) ⇒ Object



301
302
303
304
305
# File 'lib/seapig/client.rb', line 301

def patch(message)
	self[message['id']] ||= SeapigObject.new(@server, message['id'], self)
	self[message['id']].patch(message)
	@onchange_proc.call(self[message['id']]) if @onchange_proc
end

#produce(object_id, version) ⇒ Object



316
317
318
319
320
321
322
323
324
325
# File 'lib/seapig/client.rb', line 316

def produce(object_id, version)
	key = @children.keys.find { |key| key == object_id }
	child = (@children[(key or object_id)] ||= SeapigObject.new(@server, object_id, self))
	child.version_requested = version
	if @onproduce_proc
		@onproduce_proc.call(child)
	else
		child.upload(0,{},object_id)
	end
end