Class: Peach::Stream::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/peach/stream/response.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



10
11
12
# File 'lib/peach/stream/response.rb', line 10

def initialize
  @changes = []
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



8
9
10
# File 'lib/peach/stream/response.rb', line 8

def changes
  @changes
end

Instance Method Details

#add_action(action, *args, **kwargs) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/peach/stream/response.rb', line 14

def add_action(action, *args, **kwargs)
  raise Peach::BadResponseError, "Action '#{action}' is not supported" unless respond_to?(action, true)

  change = { action: action }
  change.merge! send(action, *args, **kwargs)
  @changes << change
end

#bodyObject



22
23
24
25
# File 'lib/peach/stream/response.rb', line 22

def body
  body = { changes: changes }
  JSON.generate(body)
end