Class: Amiando::Boolean

Inherits:
Object
  • Object
show all
Includes:
Autorun
Defined in:
lib/amiando/boolean.rb

Overview

This object is intended to be used when an api will return a boolean response, but due to the delayed nature of doing requests in parallel, can't be initialized from the beginning.

After the object is populated, you can ask the result with the result method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Autorun

included

Constructor Details

#initialize(response_attribute) ⇒ Boolean

Returns a new instance of Boolean.


18
19
20
# File 'lib/amiando/boolean.rb', line 18

def initialize(response_attribute)
  @response_attribute = response_attribute.to_s
end

Instance Attribute Details

#requestObject

Returns the value of attribute request


13
14
15
# File 'lib/amiando/boolean.rb', line 13

def request
  @request
end

#responseObject

Returns the value of attribute response


13
14
15
# File 'lib/amiando/boolean.rb', line 13

def response
  @response
end

#resultObject (readonly)

Returns the value of attribute result


14
15
16
# File 'lib/amiando/boolean.rb', line 14

def result
  @result
end

#successObject (readonly)

Returns the value of attribute success


14
15
16
# File 'lib/amiando/boolean.rb', line 14

def success
  @success
end

Instance Method Details

#populate(response_body) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/amiando/boolean.rb', line 22

def populate(response_body)
  if response_body.key?(@response_attribute)
    @result = response_body[@response_attribute]
    @success = response_body['success']
  else
    raise Error::NotInitialized.new("The response doesn't have the expected attribute")
  end
end