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.



175
176
177
178
179
180
181
182
183
# File 'lib/yup/request_forwarder.rb', line 175

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



193
194
195
# File 'lib/yup/request_forwarder.rb', line 193

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

#receive_data(data) ⇒ Object



185
186
187
188
189
190
191
# File 'lib/yup/request_forwarder.rb', line 185

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