Class: Request::Builder::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, context) ⇒ Result

Returns a new instance of Result.



11
12
13
14
15
16
# File 'lib/request/builder/result.rb', line 11

def initialize(response, context)
  @response = response
  @context = context
  @before_validate = config.callbacks[:before_validate]
  @body = @before_validate ? @before_validate.call(response.body) : response.body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/request/builder/result.rb', line 22

def failure?
  !success?
end

#full_errorsObject



30
31
32
# File 'lib/request/builder/result.rb', line 30

def full_errors
  errors(full: true).to_h
end

#schema_resultObject



26
27
28
# File 'lib/request/builder/result.rb', line 26

def schema_result
  @schema_result ||= schema.call(body)
end

#success?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/request/builder/result.rb', line 18

def success?
  status == 200 && schema_result.success?
end