class Typhoid::Builder
Attributes
body[R]
exception[R]
klass[R]
parsed_body[R]
response[R]
Public Class Methods
call(klass, response)
click to toggle source
# File lib/typhoid/builder.rb, line 9 def self.call(klass, response) new(klass, response).build end
new(klass, response)
click to toggle source
# 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
Public Instance Methods
build()
click to toggle source
# File lib/typhoid/builder.rb, line 25 def build array? ? build_array : build_single end
Private Instance Methods
array?()
click to toggle source
# File lib/typhoid/builder.rb, line 36 def array? parsed_body.is_a?(Array) end
build_array()
click to toggle source
# File lib/typhoid/builder.rb, line 41 def build_array parsed_body.collect { |single| build_from_klass(single) } end
build_from_klass(attributes)
click to toggle source
# File lib/typhoid/builder.rb, line 29 def build_from_klass(attributes) klass.new(attributes).tap { |item| item.after_build(response, exception) if item.respond_to? :after_build } end
build_single()
click to toggle source
# File lib/typhoid/builder.rb, line 48 def build_single build_from_klass parsed_body end
parser()
click to toggle source
# File lib/typhoid/builder.rb, line 53 def parser klass.parser end