Class: AgileProxy::RequestSpec
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AgileProxy::RequestSpec
- Defined in:
- lib/agile_proxy/model/request_spec.rb
Overview
The Request Spec model
The request spec is an input/output specification that incoming HTTP(s) requests are matched against.
It uses the action dispatch router to do this matching, which is fed data from the database as it’s input - i.e. its routing table is generated on the fly.
This model is responsible not only for retrieving and persisting these request specifications, but also for creating the response
Instance Method Summary collapse
-
#call(params, headers, body) ⇒ Array
This method’s output is a ‘rack’ response, but its input is not.
-
#conditions_json ⇒ Hash
The conditions are at present, stored as a JSON string.
-
#initialize(attrs = {}) ⇒ RequestSpec
constructor
A new instance of RequestSpec.
Constructor Details
#initialize(attrs = {}) ⇒ RequestSpec
Returns a new instance of RequestSpec.
23 24 25 26 |
# File 'lib/agile_proxy/model/request_spec.rb', line 23 def initialize(attrs = {}) attrs[:http_method] = attrs.delete(:method) if attrs.key?(:method) super end |
Instance Method Details
#call(params, headers, body) ⇒ Array
This method’s output is a ‘rack’ response, but its input is not. When the router has determined that this request spec is the one that is going to be sent to the client, it will call this method with the request’s parameters, headers and body.
if no response has been specified, an empty body will be returned, otherwise a ‘rack’ version of the response is returned
44 45 46 |
# File 'lib/agile_proxy/model/request_spec.rb', line 44 def call(params, headers, body) response.nil? ? [204, { 'Content-Type' => 'text/plain' }, ''] : response.to_rack(params, headers, body) end |
#conditions_json ⇒ Hash
The conditions are at present, stored as a JSON string. This is editable as a string in the UI, and therefore accessible using ‘conditions’ as normal. This method returns a JSON decoded version of this as a HASH
31 32 33 |
# File 'lib/agile_proxy/model/request_spec.rb', line 31 def conditions_json ActiveSupport::JSON.decode(conditions).with_indifferent_access end |