Class: Response
- Inherits:
-
Object
- Object
- Response
- Defined in:
- lib/mull/response.rb
Instance Attribute Summary collapse
-
#file_utils ⇒ Object
Returns the value of attribute file_utils.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#matcher ⇒ Object
Returns the value of attribute matcher.
-
#method ⇒ Object
Returns the value of attribute method.
-
#post_body ⇒ Object
Returns the value of attribute post_body.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#server ⇒ Object
Returns the value of attribute server.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(definition:, file_utils:, server:) ⇒ Response
constructor
A new instance of Response.
- #map_server_route ⇒ Object
Constructor Details
#initialize(definition:, file_utils:, server:) ⇒ Response
Returns a new instance of Response.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mull/response.rb', line 13 def initialize(definition:, file_utils:, server:) self.file_utils = file_utils self.server = server self.filepath = definition['file'] self.headers = definition['matcher_headers'] || {} self.method = definition['method'] || 'GET' self.post_body = definition['post_body'] || {} self.status = definition['status'] || 200 self.matcher = definition['matcher'] || definition['url'] self.response_body = definition['body'] || file_utils.read_file(path: filepath) end |
Instance Attribute Details
#file_utils ⇒ Object
Returns the value of attribute file_utils.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def file_utils @file_utils end |
#filepath ⇒ Object
Returns the value of attribute filepath.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def filepath @filepath end |
#headers ⇒ Object
Returns the value of attribute headers.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def headers @headers end |
#matcher ⇒ Object
Returns the value of attribute matcher.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def matcher @matcher end |
#method ⇒ Object
Returns the value of attribute method.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def method @method end |
#post_body ⇒ Object
Returns the value of attribute post_body.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def post_body @post_body end |
#response_body ⇒ Object
Returns the value of attribute response_body.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def response_body @response_body end |
#server ⇒ Object
Returns the value of attribute server.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def server @server end |
#status ⇒ Object
Returns the value of attribute status.
2 3 4 |
# File 'lib/mull/response.rb', line 2 def status @status end |
Instance Method Details
#map_server_route ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mull/response.rb', line 34 def map_server_route this = self server.send(method.downcase, Regexp.new(matcher)) do this.headers.each do |key, value| pass and return unless request.env["HTTP_" + key.gsub(/-/, '_').upcase] == value end this.post_body.each do |key, value| pass and return unless Regexp.new(value.to_s) === params[key] end status this.status this.response_body end end |