Class: Ari::Resource

Inherits:
Model
  • Object
show all
Defined in:
lib/ari/resource.rb

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


9
10
11
12
13
# File 'lib/ari/resource.rb', line 9

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


15
16
17
18
19
20
21
# File 'lib/ari/resource.rb', line 15

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


4
5
6
7
# File 'lib/ari/resource.rb', line 4

def client(options = {})
  return @client if @client
  self.class.client(options)
end

#remove_all_listeners!Object Also known as: off_all!


31
32
33
34
35
# File 'lib/ari/resource.rb', line 31

def remove_all_listeners!
  client.class.instance_listeners.each do |type, _|
    remove_listener type
  end
end

#remove_listener(type) ⇒ Object Also known as: off


24
25
26
27
28
# File 'lib/ari/resource.rb', line 24

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