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.



141
142
143
144
145
146
147
148
# File 'lib/api_resource/mocks.rb', line 141

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.



140
141
142
# File 'lib/api_resource/mocks.rb', line 140

def block
  @block
end

#bodyObject (readonly)

Returns the value of attribute body.

Raises:

  • (Exception)


140
141
142
# File 'lib/api_resource/mocks.rb', line 140

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



140
141
142
# File 'lib/api_resource/mocks.rb', line 140

def code
  @code
end

#formatObject (readonly)

Returns the value of attribute format.



140
141
142
# File 'lib/api_resource/mocks.rb', line 140

def format
  @format
end

#headersObject (readonly)

Returns the value of attribute headers.



140
141
142
# File 'lib/api_resource/mocks.rb', line 140

def headers
  @headers
end

Instance Method Details

#[](key) ⇒ Object



152
153
154
# File 'lib/api_resource/mocks.rb', line 152

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

#[]=(key, val) ⇒ Object



149
150
151
# File 'lib/api_resource/mocks.rb', line 149

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

#body_as_objectObject



161
162
163
# File 'lib/api_resource/mocks.rb', line 161

def body_as_object
  return @body
end

#generate_response(params) ⇒ Object



165
166
167
# File 'lib/api_resource/mocks.rb', line 165

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