Class: HTTPX::Transcoder::Body::Encoder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/httpx/transcoder/body.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Encoder

Returns a new instance of Encoder.



16
17
18
# File 'lib/httpx/transcoder/body.rb', line 16

def initialize(body)
  @raw = body
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



46
47
48
49
50
51
52
# File 'lib/httpx/transcoder/body.rb', line 46

def method_missing(meth, *args, &block)
  if @raw.respond_to?(meth)
    @raw.__send__(meth, *args, &block)
  else
    super
  end
end

Instance Method Details

#bytesizeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/httpx/transcoder/body.rb', line 20

def bytesize
  if @raw.respond_to?(:bytesize)
    @raw.bytesize
  elsif @raw.respond_to?(:to_ary)
    @raw.map(&:bytesize).reduce(0, :+)
  elsif @raw.respond_to?(:size)
    @raw.size || Float::INFINITY
  elsif @raw.respond_to?(:length)
    @raw.length || Float::INFINITY
  elsif @raw.respond_to?(:each)
    Float::INFINITY
  else
    raise Error, "cannot determine size of body: #{@raw.inspect}"
  end
end

#content_typeObject



36
37
38
# File 'lib/httpx/transcoder/body.rb', line 36

def content_type
  "application/octet-stream"
end