Class: Sabbath::Server::DeferrableBody

Inherits:
Object
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/sabbath/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#jsonp_callbackObject

Returns the value of attribute jsonp_callback.



51
52
53
# File 'lib/sabbath/server.rb', line 51

def jsonp_callback
  @jsonp_callback
end

Instance Method Details

#call(body) ⇒ Object



53
54
55
56
57
# File 'lib/sabbath/server.rb', line 53

def call(body)
  body.each do |chunk|
    @body_callback.call(chunk)
  end
end

#each(&blk) ⇒ Object



59
60
61
# File 'lib/sabbath/server.rb', line 59

def each(&blk)
  @body_callback = blk
end

#succeed_with(body) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sabbath/server.rb', line 63

def succeed_with(body)
  data = if jsonp_callback 
    "#{jsonp_callback}(#{body.to_json})"
  else
    body.to_json
  end
  
  puts "sending #{data.inspect}"
  call(Array(data))
  succeed
end