Class: DDP::Server::Protocol::Data::Subscription

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/ddp/server/protocol/data.rb

Overview

Actor that asynchronously monitors a collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener, id, name, query) ⇒ Subscription

Returns a new instance of Subscription.



90
91
92
93
94
95
96
# File 'lib/ddp/server/protocol/data.rb', line 90

def initialize(listener, id, name, query)
	@stopped = false
	@name = name
	@listener = listener
	@id = id
	@query = query
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



87
88
89
# File 'lib/ddp/server/protocol/data.rb', line 87

def id
  @id
end

#listenerObject (readonly)

Returns the value of attribute listener.



87
88
89
# File 'lib/ddp/server/protocol/data.rb', line 87

def listener
  @listener
end

#nameObject (readonly)

Returns the value of attribute name.



87
88
89
# File 'lib/ddp/server/protocol/data.rb', line 87

def name
  @name
end

#queryObject (readonly)

Returns the value of attribute query.



87
88
89
# File 'lib/ddp/server/protocol/data.rb', line 87

def query
  @query
end

#stoppedObject (readonly) Also known as: stopped?

Returns the value of attribute stopped.



87
88
89
# File 'lib/ddp/server/protocol/data.rb', line 87

def stopped
  @stopped
end

Instance Method Details

#startObject



98
99
100
101
102
103
# File 'lib/ddp/server/protocol/data.rb', line 98

def start
	query.call do |old_value, new_value|
		listener.subscription_update(id, old_value, new_value)
		break if stopped?
	end
end

#stopObject



105
106
107
# File 'lib/ddp/server/protocol/data.rb', line 105

def stop
	@stopped = true
end