Class: Yup::State::FeedbackHandler

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/yup/request_forwarder.rb

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ FeedbackHandler

Returns a new instance of FeedbackHandler.



163
164
165
166
167
168
169
170
171
# File 'lib/yup/request_forwarder.rb', line 163

def initialize(state)
  @state      = state

  @yajl   = Yajl::Parser.new(:symbolize_keys => true)
  @yajl.on_parse_complete = method(:on_message)

  @logger = Yup.logger.clone
  @logger.progname = "Yup::State::FeedbackHandler"
end

Instance Method Details

#on_message(req) ⇒ Object



181
182
183
# File 'lib/yup/request_forwarder.rb', line 181

def on_message(req)
  @state.push(Yajl::Encoder.encode(req))
end

#receive_data(data) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/yup/request_forwarder.rb', line 173

def receive_data(data)
  begin
    @yajl << data
  rescue Yajl::ParseError
    @logger.error { "Error while parsing \"#{data}\"" }
  end
end