lib/hara/app.rb in hara-0.0.2 vs lib/hara/app.rb in hara-0.1.0
- old
+ new
@@ -44,18 +44,21 @@
#after_authentication only called when authentication succeeded
def after_authentication
end
- def before_process action, args
+ def before_action action, args
end
- def after_process action, args
+ def after_action action, args
end
+ def after_process
+ end
+
def action_missing action, args
- warn "#{Time.now} : #{socket.remote_ip} request action: #{action} args: #{args}, action not defined"
+ info " #{socket.remote_ip} request action: #{action} args: #{args.inspect}, action not defined"
end
def command
@command || {}
end
@@ -69,11 +72,11 @@
async.setup
end
def setup
init
- info "#{Time.now} : #{socket.remote_ip} coming"
+ info "#{socket.remote_ip} coming"
unless authentication
authentication_failed
else
after_authentication
async.run
@@ -87,11 +90,11 @@
terminate
return
end
end
rescue Reel::SocketError, EOFError #client disconnect
- info "#{Time.now} : #{@socket.remote_ip} disconnect, user: #{@user ? @user.id : "none"}"
+ info "#{socket.remote_ip} disconnect"
begin
@closed = true unless @closed
on_close
ensure
terminate
@@ -100,20 +103,21 @@
def process message
@command = JSON.parse(message)
action = @command["action"]
args = @command["args"]
- info "#{Time.now} : #{@socket.remote_ip} request action: #{action}"
- before_process action, *args
+ info "#{socket.remote_ip} request action: #{action} args: #{args.inspect}"
+ before_action action, *args
call_action action, *args
+ after_action action, *args
rescue JSON::ParserError
- warn "#{Time.now} : #{@socket.remote_ip} message can't parse"
+ info "#{socket.remote_ip} message can't parse"
terminate
rescue StandardError => e
- warn "#{Time.now} : #{@socket.remote_ip} want action: #{action} args: #{args} but process error:\n#{e.inspect}"
+ info "#{socket.remote_ip} processing error:\n#{e.inspect}"
terminate
ensure
- after_process action, *args
+ after_process
end
def call_action action, *args
if Actions.has_key? action
Actions[action].bind(self).call *args