Class: Ari::Resource
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
#attributes=, #initialize
Constructor Details
This class inherits a constructor from Ari::Model
Class Method Details
.client(options = {}) ⇒ Object
10
11
12
13
14
|
# File 'lib/ari/resource.rb', line 10
def self.client(options = {})
client = options.fetch(:client, nil)
return client if client
Ari.client
end
|
Instance Method Details
#add_listener(type, params = {}, &block) ⇒ Object
Also known as:
on
16
17
18
19
20
21
22
|
# File 'lib/ari/resource.rb', line 16
def add_listener(type, params = {}, &block)
client.class.instance_listeners[type.to_sym] ||= []
unless client.class.instance_listeners[type.to_sym].any? { |l| l.id == self.id }
client.class.instance_listeners[type.to_sym] << self
end
client.add_listener "#{type}-#{self.id}", params, &block
end
|
#client(options = {}) ⇒ Object
5
6
7
8
|
# File 'lib/ari/resource.rb', line 5
def client(options = {})
return @client if @client
self.class.client(options)
end
|
#remove_all_listeners! ⇒ Object
Also known as:
off_all!
32
33
34
35
36
|
# File 'lib/ari/resource.rb', line 32
def remove_all_listeners!
client.class.instance_listeners.each do |type, _|
remove_listener type
end
end
|
#remove_listener(type) ⇒ Object
Also known as:
off
25
26
27
28
29
|
# File 'lib/ari/resource.rb', line 25
def remove_listener(type)
client.class.instance_listeners[type.to_sym] ||= []
client.class.instance_listeners[type].delete_if { |i| i.id == self.id }
client.remove_listener "#{type}-#{self.id}"
end
|