Module: SockJS::Endpoint::ClassMethods

Included in:
SockJS::Endpoint
Defined in:
lib/sockjs/transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



99
100
101
# File 'lib/sockjs/transport.rb', line 99

def method
  @method
end

#prefixObject (readonly)

Returns the value of attribute prefix.



99
100
101
# File 'lib/sockjs/transport.rb', line 99

def prefix
  @prefix
end

Instance Method Details

#add_route(route_set, connection, options) ⇒ Object



85
86
87
88
# File 'lib/sockjs/transport.rb', line 85

def add_route(route_set, connection, options)
  #SockJS.debug "Adding route for #{self} on #{route_conditions.inspect}"
  route_set.add_route(self.new(connection, options), route_conditions, {})
end

#add_routes(route_set, connection, options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/sockjs/transport.rb', line 58

def add_routes(route_set, connection, options)
  method_catching = Hash.new{|h,k| h[k] = []}
  endpoints.each do |endpoint_class|
    endpoint_class.add_route(route_set, connection, options)
    method_catching[endpoint_class.routing_prefix] << endpoint_class.method
  end
  method_catching.each_pair do |prefix, methods|
    route_set.add_route(MethodNotSupportedApp.new(methods), {:path_info => prefix}, {})
  end
end

#endpointsObject



90
91
92
# File 'lib/sockjs/transport.rb', line 90

def endpoints
  @endpoints ||= []
end

#register(method, prefix) ⇒ Object



94
95
96
97
98
# File 'lib/sockjs/transport.rb', line 94

def register(method, prefix)
  @prefix = prefix
  @method = method
  Endpoint.endpoints << self
end

#route_conditionsObject



78
79
80
81
82
83
# File 'lib/sockjs/transport.rb', line 78

def route_conditions
  {
    :request_method => self.method,
    :path_info => self.routing_prefix
  }
end

#routing_prefixObject



69
70
71
72
73
74
75
76
# File 'lib/sockjs/transport.rb', line 69

def routing_prefix
  case prefix
  when String
    "/" + prefix
  when Regexp
    prefix
  end
end