Class: ApiResource::Mocks::MockResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/api_resource/mocks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, opts = {}, &block) ⇒ MockResponse

Returns a new instance of MockResponse.



147
148
149
150
151
152
153
154
# File 'lib/api_resource/mocks.rb', line 147

def initialize(body, opts = {}, &block)
  opts = opts.reverse_merge({:headers => {}, :status_code => 200})
  @body = body
  @headers = opts[:headers]
  @code = opts[:status_code]
  @format = (opts[:format] || :json)
  @block = block if block_given?
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



146
147
148
# File 'lib/api_resource/mocks.rb', line 146

def block
  @block
end

#bodyObject (readonly)

Returns the value of attribute body.

Raises:

  • (Exception)


146
147
148
# File 'lib/api_resource/mocks.rb', line 146

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



146
147
148
# File 'lib/api_resource/mocks.rb', line 146

def code
  @code
end

#formatObject (readonly)

Returns the value of attribute format.



146
147
148
# File 'lib/api_resource/mocks.rb', line 146

def format
  @format
end

#headersObject (readonly)

Returns the value of attribute headers.



146
147
148
# File 'lib/api_resource/mocks.rb', line 146

def headers
  @headers
end

Instance Method Details

#[](key) ⇒ Object



158
159
160
# File 'lib/api_resource/mocks.rb', line 158

def [](key)
  @headers[key]
end

#[]=(key, val) ⇒ Object



155
156
157
# File 'lib/api_resource/mocks.rb', line 155

def []=(key, val)
  @headers[key] = val
end

#body_as_objectObject



167
168
169
# File 'lib/api_resource/mocks.rb', line 167

def body_as_object
  return @body
end

#generate_response(params) ⇒ Object



171
172
173
# File 'lib/api_resource/mocks.rb', line 171

def generate_response(params)
  @body = @body.instance_exec(params, &self.block) if self.block
end