Class: AjaxChat
- Inherits:
-
Object
- Object
- AjaxChat
- Defined in:
- lib/h2g_ajaxchat.rb
Instance Attribute Summary collapse
-
#rws ⇒ Object
readonly
Returns the value of attribute rws.
Instance Method Summary collapse
- #chatter(newmsg = nil) ⇒ Object
- #index ⇒ Object
-
#initialize(chatobj, rws = DummyRws.new(self), config: nil, debug: false) ⇒ AjaxChat
constructor
A new instance of AjaxChat.
- #login ⇒ Object
- #login_post(username) ⇒ Object
- #logout ⇒ Object
- #logout_post ⇒ Object
-
#messages ⇒ Object
user for debugging.
- #req(obj) ⇒ Object
-
#users ⇒ Object
user for debugging.
Constructor Details
#initialize(chatobj, rws = DummyRws.new(self), config: nil, debug: false) ⇒ AjaxChat
Returns a new instance of AjaxChat.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/h2g_ajaxchat.rb', line 338 def initialize(chatobj, rws=DummyRws.new(self), config: nil, debug: false) @chat, @rws, @debug = chatobj, rws, debug plugins = if config then SimpleConfig.new(config).to_h.map do |name, settings| settings = {} if settings.is_a? String pluginklass_name = 'AjaxChatPlugin' + name.to_s Kernel.const_get(pluginklass_name).new(settings) end else [] end @h = {} @index, @login, @logout, @logout_post = \ [Index, Login, Logout, LogoutPost].map do |klass| obj = klass.new @h plugins.each {|plugin| plugin.apply obj } obj end end |
Instance Attribute Details
#rws ⇒ Object (readonly)
Returns the value of attribute rws.
336 337 338 |
# File 'lib/h2g_ajaxchat.rb', line 336 def rws @rws end |
Instance Method Details
#chatter(newmsg = nil) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/h2g_ajaxchat.rb', line 375 def chatter(newmsg=nil) id, users = @rws.req.session[:session_id].to_s, @chat.users @chat.chatter(@rws.req, newmsg) do |t, uid, username, msg| s2 = if id == uid then "you: %s" % msg else "%s: %s" % [users[uid], msg] end "<p><span id='time'>%s</span> %s</p>" % [t.strftime("%H:%M:%S"), s2] end end |
#index ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/h2g_ajaxchat.rb', line 420 def index() if @rws.req.session[:username] then @h[:username] = @rws.req.session[:username] view @index else @rws.redirect 'login' end end |
#login ⇒ Object
393 394 395 396 397 |
# File 'lib/h2g_ajaxchat.rb', line 393 def login() view @login end |
#login_post(username) ⇒ Object
399 400 401 402 403 404 405 |
# File 'lib/h2g_ajaxchat.rb', line 399 def login_post(username) @chat.login @rws.req, username @h[:username] = username @rws.redirect 'index' end |
#logout ⇒ Object
407 408 409 410 411 |
# File 'lib/h2g_ajaxchat.rb', line 407 def logout() view @logout end |
#logout_post ⇒ Object
413 414 415 416 417 418 |
# File 'lib/h2g_ajaxchat.rb', line 413 def logout_post() @chat.logout @rws.req view @logout_post end |
#messages ⇒ Object
user for debugging
436 437 438 |
# File 'lib/h2g_ajaxchat.rb', line 436 def () @chat. end |
#req(obj) ⇒ Object
440 441 442 443 444 445 |
# File 'lib/h2g_ajaxchat.rb', line 440 def req(obj) @rws.req = obj self end |
#users ⇒ Object
user for debugging
448 449 450 |
# File 'lib/h2g_ajaxchat.rb', line 448 def users() @chat.users end |