Module: EM::JsonConnection::Base
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #init_parser ⇒ Object
- #json_parsed(hash) ⇒ Object
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #send_data(data) ⇒ Object
- #unbind ⇒ Object
Instance Method Details
#connected? ⇒ Boolean
33 34 35 |
# File 'lib/em_json_connection.rb', line 33 def connected? @connect_status end |
#init_parser ⇒ Object
13 14 15 16 |
# File 'lib/em_json_connection.rb', line 13 def init_parser @parser = Yajl::Parser.new(:symbolize_keys => true) @parser.on_parse_complete = method(:json_parsed) end |
#json_parsed(hash) ⇒ Object
25 26 27 |
# File 'lib/em_json_connection.rb', line 25 def json_parsed(hash) puts 'to be implemented in the subclass' end |
#post_init ⇒ Object
7 8 9 10 11 |
# File 'lib/em_json_connection.rb', line 7 def post_init init_parser @encoder = Yajl::Encoder.new @connect_status = true end |
#receive_data(data) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/em_json_connection.rb', line 18 def receive_data(data) @parser << data rescue Yajl::ParseError => error puts "Yajl::ParseError: #{error}" init_parser end |
#send_data(data) ⇒ Object
29 30 31 |
# File 'lib/em_json_connection.rb', line 29 def send_data(data) super @encoder.encode(data) end |
#unbind ⇒ Object
37 38 39 |
# File 'lib/em_json_connection.rb', line 37 def unbind @connect_status = false end |