Module: Faye

Defined in:
lib/faye.rb,
lib/faye/error.rb,
lib/faye/engines/proxy.rb,
lib/faye/engines/memory.rb,
lib/faye/mixins/logging.rb,
lib/faye/transport/http.rb,
lib/faye/util/namespace.rb,
lib/faye/mixins/timeouts.rb,
lib/faye/protocol/client.rb,
lib/faye/protocol/server.rb,
lib/faye/protocol/socket.rb,
lib/faye/transport/local.rb,
lib/faye/mixins/publisher.rb,
lib/faye/protocol/channel.rb,
lib/faye/protocol/grammar.rb,
lib/faye/mixins/deferrable.rb,
lib/faye/protocol/envelope.rb,
lib/faye/engines/connection.rb,
lib/faye/protocol/extensible.rb,
lib/faye/transport/transport.rb,
lib/faye/protocol/publication.rb,
lib/faye/transport/web_socket.rb,
lib/faye/adapters/rack_adapter.rb,
lib/faye/protocol/subscription.rb,
lib/faye/adapters/static_server.rb

Defined Under Namespace

Modules: Deferrable, Engine, Extensible, Grammar, Logging, Publisher, Timeouts Classes: Channel, Client, Envelope, Error, Namespace, Publication, RackAdapter, Server, StaticServer, Subscription, Transport

Constant Summary collapse

VERSION =
'1.0.1'
ROOT =
File.expand_path(File.dirname(__FILE__))
BAYEUX_VERSION =
'1.0'
JSONP_CALLBACK =
'jsonpcallback'
CONNECTION_TYPES =
%w[long-polling cross-origin-long-polling callback-polling websocket eventsource in-process]
MANDATORY_CONNECTION_TYPES =
%w[long-polling callback-polling in-process]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



52
53
54
# File 'lib/faye.rb', line 52

def logger
  @logger
end

Class Method Details

.async_each(list, iterator, callback) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/faye.rb', line 95

def self.async_each(list, iterator, callback)
  n       = list.size
  i       = -1
  calls   = 0
  looping = false

  loop, resume = nil, nil

  iterate = lambda do
    calls -= 1
    i += 1
    if i == n
      callback.call if callback
    else
      iterator.call(list[i], resume)
    end
  end

  loop = lambda do
    unless looping
      looping = true
      iterate.call while calls > 0
      looping = false
    end
  end

  resume = lambda do
    calls += 1
    loop.call
  end
  resume.call
end

.client_id_from_messages(messages) ⇒ Object



63
64
65
66
# File 'lib/faye.rb', line 63

def self.client_id_from_messages(messages)
  first = [messages].flatten.find { |m| m['channel'] == '/meta/connect' }
  first && first['clientId']
end

.copy_object(object) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/faye.rb', line 68

def self.copy_object(object)
  case object
  when Hash
    clone = {}
    object.each { |k,v| clone[k] = copy_object(v) }
    clone
  when Array
    clone = []
    object.each { |v| clone << copy_object(v) }
    clone
  else
    object
  end
end

.ensure_reactor_running!Object



55
56
57
# File 'lib/faye.rb', line 55

def self.ensure_reactor_running!
  Engine.ensure_reactor_running!
end

.parse_url(url) ⇒ Object



83
84
85
# File 'lib/faye.rb', line 83

def self.parse_url(url)
  String === url ? URI.parse(url) : url
end

.random(*args) ⇒ Object



59
60
61
# File 'lib/faye.rb', line 59

def self.random(*args)
  Engine.random(*args)
end

.to_json(value) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/faye.rb', line 87

def self.to_json(value)
  case value
    when Hash, Array then MultiJson.dump(value)
    when String, NilClass then value.inspect
    else value.to_s
  end
end