Module: Hara::App
- Defined in:
- lib/hara/app.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- Actions =
{}
Instance Attribute Summary collapse
-
#client_ip ⇒ Object
readonly
Returns the value of attribute client_ip.
-
#client_port ⇒ Object
readonly
Returns the value of attribute client_port.
-
#handshake ⇒ Object
readonly
Returns the value of attribute handshake.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
-
#action_missing(action, args) ⇒ Object
like method_missing.
- #after_action(action, args) ⇒ Object
-
#after_connect ⇒ Object
callback methods.
- #app_finalizer ⇒ Object
- #before_action(action, args) ⇒ Object
- #call_action(action, *args) ⇒ Object
- #hara_setup ⇒ Object
-
#headers ⇒ Object
get client headers.
-
#initialize(handshake, socket) ⇒ Object
below are internal functions(should not been overriding).
- #on_close ⇒ Object
- #process_msg(message) ⇒ Object
Instance Attribute Details
#client_ip ⇒ Object (readonly)
Returns the value of attribute client_ip.
28 29 30 |
# File 'lib/hara/app.rb', line 28 def client_ip @client_ip end |
#client_port ⇒ Object (readonly)
Returns the value of attribute client_port.
28 29 30 |
# File 'lib/hara/app.rb', line 28 def client_port @client_port end |
#handshake ⇒ Object (readonly)
Returns the value of attribute handshake.
28 29 30 |
# File 'lib/hara/app.rb', line 28 def handshake @handshake end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
28 29 30 |
# File 'lib/hara/app.rb', line 28 def socket @socket end |
Class Method Details
.included(klass) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/hara/app.rb', line 33 def included klass klass.send :include, Celluloid klass.send :include, Celluloid::Logger klass.send :finalizer, :app_finalizer klass.send :extend, ClassMethods ::Hara.const_set :Application, klass end |
Instance Method Details
#action_missing(action, args) ⇒ Object
like method_missing
70 71 72 73 |
# File 'lib/hara/app.rb', line 70 def action_missing action, args info "#{client_ip} request action: #{action} args: #{args.inspect}, action not defined" raise NoMethodError, "undefined action '#{action}' for #{self}:#{self.class}" end |
#after_action(action, args) ⇒ Object
61 62 |
# File 'lib/hara/app.rb', line 61 def after_action action, args end |
#after_connect ⇒ Object
callback methods
55 56 |
# File 'lib/hara/app.rb', line 55 def after_connect end |
#app_finalizer ⇒ Object
113 114 115 116 117 |
# File 'lib/hara/app.rb', line 113 def app_finalizer on_close ensure @socket.close if @socket end |
#before_action(action, args) ⇒ Object
58 59 |
# File 'lib/hara/app.rb', line 58 def before_action action, args end |
#call_action(action, *args) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/hara/app.rb', line 105 def call_action action, *args if Actions.has_key? action Actions[action].bind(self).call *args else action_missing action, *args end end |
#hara_setup ⇒ Object
89 90 91 92 |
# File 'lib/hara/app.rb', line 89 def hara_setup info "#{client_ip} coming" after_connect end |
#headers ⇒ Object
get client headers
76 77 78 |
# File 'lib/hara/app.rb', line 76 def headers handshake.headers_downcased end |
#initialize(handshake, socket) ⇒ Object
below are internal functions(should not been overriding)
82 83 84 85 86 87 |
# File 'lib/hara/app.rb', line 82 def initialize handshake, socket @handshake = handshake @socket = socket @client_port, @client_ip = Socket.unpack_sockaddr_in(socket.get_peername) #to get ip address of user async.hara_setup end |
#on_close ⇒ Object
64 65 |
# File 'lib/hara/app.rb', line 64 def on_close end |
#process_msg(message) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hara/app.rb', line 94 def process_msg action, args = Hara.decode_msg() info "#{client_ip} request action: #{action} args: #{args.inspect}" before_action action, *args call_action action, *args after_action action, *args rescue StandardError => e info "#{client_ip} processing error:\n#{e.inspect}" terminate end |