Class: Protocol::HTTP::Body::Wrapper

Inherits:
Readable
  • Object
show all
Defined in:
lib/protocol/http/body/wrapper.rb

Overview

Wrapping body instance. Typically you’d override ‘#read`.

Direct Known Subclasses

Completable, Digestable, Rewindable, ZStream

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Readable

#call, #each, #finish, #join, #stream?

Constructor Details

#initialize(body) ⇒ Wrapper

Initialize the wrapper with the given body.



26
27
28
# File 'lib/protocol/http/body/wrapper.rb', line 26

def initialize(body)
	@body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



31
32
33
# File 'lib/protocol/http/body/wrapper.rb', line 31

def body
  @body
end

Class Method Details

.wrap(message) ⇒ Object

Wrap the body of the given message in a new instance of this class.



17
18
19
20
21
# File 'lib/protocol/http/body/wrapper.rb', line 17

def self.wrap(message)
	if body = message.body
		message.body = self.new(body)
	end
end

Instance Method Details

#as_jsonObject

Convert the body to a hash suitable for serialization.



86
87
88
89
90
91
# File 'lib/protocol/http/body/wrapper.rb', line 86

def as_json(...)
	{
		class: self.class.name,
		body: @body&.as_json
	}
end

#bufferedObject

Forwards to the wrapped body.



54
55
56
# File 'lib/protocol/http/body/wrapper.rb', line 54

def buffered
	@body.buffered
end

#close(error = nil) ⇒ Object

Close the body.



36
37
38
39
40
41
# File 'lib/protocol/http/body/wrapper.rb', line 36

def close(error = nil)
	@body.close(error)
	
	# It's a no-op:
	# super
end

#discardObject

Forwards to the wrapped body.



79
80
81
# File 'lib/protocol/http/body/wrapper.rb', line 79

def discard
	@body.discard
end

#empty?Boolean

Forwards to the wrapped body.

Returns:

  • (Boolean)


44
45
46
# File 'lib/protocol/http/body/wrapper.rb', line 44

def empty?
	@body.empty?
end

#inspectObject

Inspect the wrapped body. The wrapper, by default, is transparent.



103
104
105
# File 'lib/protocol/http/body/wrapper.rb', line 103

def inspect
	@body.inspect
end

#lengthObject

Forwards to the wrapped body.



69
70
71
# File 'lib/protocol/http/body/wrapper.rb', line 69

def length
	@body.length
end

#readObject

Forwards to the wrapped body.



74
75
76
# File 'lib/protocol/http/body/wrapper.rb', line 74

def read
	@body.read
end

#ready?Boolean

Forwards to the wrapped body.

Returns:

  • (Boolean)


49
50
51
# File 'lib/protocol/http/body/wrapper.rb', line 49

def ready?
	@body.ready?
end

#rewindObject

Forwards to the wrapped body.



59
60
61
# File 'lib/protocol/http/body/wrapper.rb', line 59

def rewind
	@body.rewind
end

#rewindable?Boolean

Forwards to the wrapped body.

Returns:

  • (Boolean)


64
65
66
# File 'lib/protocol/http/body/wrapper.rb', line 64

def rewindable?
	@body.rewindable?
end

#The wrapped body.=(wrappedbody. = (value)) ⇒ Object



31
# File 'lib/protocol/http/body/wrapper.rb', line 31

attr :body

#to_jsonObject

Convert the body to JSON.



96
97
98
# File 'lib/protocol/http/body/wrapper.rb', line 96

def to_json(...)
	as_json.to_json(...)
end