Class: Typhoid::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoid/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, response) ⇒ Builder

Returns a new instance of Builder.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/typhoid/builder.rb', line 13

def initialize(klass, response)
  @klass = klass
  @response = response
  @body = response.body
  begin
    @parsed_body = parser.call body
  rescue StandardError, ReadError => e
    @parsed_body = {}
    @exception = e
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/typhoid/builder.rb', line 5

def body
  @body
end

#exceptionObject (readonly)

Returns the value of attribute exception.



7
8
9
# File 'lib/typhoid/builder.rb', line 7

def exception
  @exception
end

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/typhoid/builder.rb', line 3

def klass
  @klass
end

#parsed_bodyObject (readonly)

Returns the value of attribute parsed_body.



6
7
8
# File 'lib/typhoid/builder.rb', line 6

def parsed_body
  @parsed_body
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/typhoid/builder.rb', line 4

def response
  @response
end

Class Method Details

.call(klass, response) ⇒ Object



9
10
11
# File 'lib/typhoid/builder.rb', line 9

def self.call(klass, response)
  new(klass, response).build
end

Instance Method Details

#buildObject



25
26
27
# File 'lib/typhoid/builder.rb', line 25

def build
  array? ? build_array : build_single
end