Class: OldApiResource::Mocks::MockResponse
- Inherits:
-
Object
- Object
- OldApiResource::Mocks::MockResponse
- Defined in:
- lib/old_api_resource/mocks.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #body_as_object ⇒ Object
- #generate_response(params) ⇒ Object
-
#initialize(body, opts = {}, &block) ⇒ MockResponse
constructor
A new instance of MockResponse.
Constructor Details
#initialize(body, opts = {}, &block) ⇒ MockResponse
Returns a new instance of MockResponse.
132 133 134 135 136 137 138 139 |
# File 'lib/old_api_resource/mocks.rb', line 132 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
#block ⇒ Object (readonly)
Returns the value of attribute block.
131 132 133 |
# File 'lib/old_api_resource/mocks.rb', line 131 def block @block end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
131 132 133 |
# File 'lib/old_api_resource/mocks.rb', line 131 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
131 132 133 |
# File 'lib/old_api_resource/mocks.rb', line 131 def code @code end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
131 132 133 |
# File 'lib/old_api_resource/mocks.rb', line 131 def format @format end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
131 132 133 |
# File 'lib/old_api_resource/mocks.rb', line 131 def headers @headers end |
Instance Method Details
#[](key) ⇒ Object
143 144 145 |
# File 'lib/old_api_resource/mocks.rb', line 143 def [](key) @headers[key] end |
#[]=(key, val) ⇒ Object
140 141 142 |
# File 'lib/old_api_resource/mocks.rb', line 140 def []=(key, val) @headers[key] = val end |
#body_as_object ⇒ Object
152 153 154 |
# File 'lib/old_api_resource/mocks.rb', line 152 def body_as_object return @body end |
#generate_response(params) ⇒ Object
156 157 158 |
# File 'lib/old_api_resource/mocks.rb', line 156 def generate_response(params) @body = @body.instance_exec(params, &self.block) if self.block end |