Class: Riddl::Protocols::HTTP::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/http/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, headers) ⇒ Generator

Returns a new instance of Generator.



35
36
37
38
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 35

def initialize(params,headers)
  @params = params
  @headers = headers
end

Class Method Details

.merge(parts) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 40

def self.merge(parts)
  parts.map do |p|
    if p.respond_to?(:read)
      p.rewind if p.respond_to?(:rewind)
      p.read
    else
      p.to_s
    end
  end.join
end

Instance Method Details

#generate(mode = :output) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 51

def generate(mode=:output)
  if @params.is_a?(Array) && @params.length == 1
    body(@params[0],mode)
  elsif @params.class == Riddl::Parameter::Simple || @params.class == Riddl::Parameter::Complex
    body(@params,mode)
  elsif @params.is_a?(Array) && @params.length > 1
    multipart(mode)
  else
    if mode == :output
      @headers['Content-Type'] = 'text/plain'
    end
    []
  end
end