Class: Primer::RealTime

Inherits:
Faye::RackAdapter
  • Object
show all
Defined in:
lib/primer/real_time.rb

Defined Under Namespace

Classes: ClientAuth, ServerAuth

Constant Summary collapse

BAYEUX_CONFIG =
{:mount => '/primer/bayeux', :timeout => 25}
SCRIPT_PATH =
'/primer.js'
TYPE_SCRIPT =
{'Content-Type' => 'text/javascript'}
SCRIPT_SOURCE =
File.read(ROOT + '/javascript/primer.js')

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RealTime

Returns a new instance of RealTime.


36
37
38
39
# File 'lib/primer/real_time.rb', line 36

def initialize(app)
  super(app, BAYEUX_CONFIG)
  add_extension(ServerAuth.new)
end

Class Attribute Details

.bayeux_serverObject

Returns the value of attribute bayeux_server


48
49
50
# File 'lib/primer/real_time.rb', line 48

def bayeux_server
  @bayeux_server
end

.passwordObject

Returns the value of attribute password


48
49
50
# File 'lib/primer/real_time.rb', line 48

def password
  @password
end

Class Method Details

.dom_id(cache_key) ⇒ Object


50
51
52
# File 'lib/primer/real_time.rb', line 50

def dom_id(cache_key)
  "primer#{ ('-' + cache_key).gsub(/[^a-z0-9]+/i, '-') }"
end

.publish(cache_key, value) ⇒ Object


54
55
56
57
58
59
60
# File 'lib/primer/real_time.rb', line 54

def publish(cache_key, value)
  return unless Primer.real_time
  client.publish(cache_key,
    :dom_id  => dom_id(cache_key),
    :content => value
  )
end

Instance Method Details

#call(env) ⇒ Object


41
42
43
44
45
# File 'lib/primer/real_time.rb', line 41

def call(env)
  request = Rack::Request.new(env)
  return super unless request.path_info == SCRIPT_PATH
  [200, TYPE_SCRIPT, [SCRIPT_SOURCE]]
end