Class: Push::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/push/configuration.rb

Defined Under Namespace

Classes: AMQP, LongPoll, WebSocket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



24
25
26
27
28
29
30
31
# File 'lib/push/configuration.rb', line 24

def initialize
  @amqp = AMQP.new('127.0.0.1', 5672, 'guest', 'guest', '/', 5)
  @web_socket = WebSocket.new('ws://localhost:3000/_push')
  @long_poll = LongPoll.new('http://localhost:3000/_push', 30)
  @backend = :amqp
  @logger = Logger.new($stdout)
  @exception_reporter = Proc.new{|e| logger.error(e) }
end

Instance Attribute Details

#amqpObject

Returns the value of attribute amqp.



3
4
5
# File 'lib/push/configuration.rb', line 3

def amqp
  @amqp
end

#backendObject

Returns the value of attribute backend.



3
4
5
# File 'lib/push/configuration.rb', line 3

def backend
  @backend
end

#exception_handlerObject

Returns the value of attribute exception_handler.



3
4
5
# File 'lib/push/configuration.rb', line 3

def exception_handler
  @exception_handler
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/push/configuration.rb', line 3

def logger
  @logger
end

#long_pollObject

Returns the value of attribute long_poll.



3
4
5
# File 'lib/push/configuration.rb', line 3

def long_poll
  @long_poll
end

#web_socketObject

Returns the value of attribute web_socket.



3
4
5
# File 'lib/push/configuration.rb', line 3

def web_socket
  @web_socket
end

Instance Method Details

#from_hash(hash) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/push/configuration.rb', line 33

def from_hash(hash)
  # Pick a backend doofus
  self.backend = hash['backend'] if hash['backend']

  # WS setup
  if web_socket = hash['web_socket']
    self.web_socket.url = web_socket['url'] if web_socket['url']
  end
  
  # HTTP longpoll setup
  if long_poll = hash['long_poll']
    self.long_poll.url = long_poll['url'] if long_poll['url']
    self.long_poll.timeout = long_poll['timeout'] if long_poll['timeout']
  end

  # Setup AMQP
  if amqp = hash['amqp']
    %w[host port username password vhost queue_ttl].each do |key|
      self.amqp.send("#{key}=", amqp[key]) if amqp[key]
    end
  end
end