Module: Soaspec::RequestBuilder
- Included in:
- Exchange
- Defined in:
- lib/soaspec/exchange/request_builder.rb
Overview
Methods to help build a Request
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Set a parameter request in the request body.
-
#method=(method) ⇒ Object
Specify HTTP method to use.
-
#method_missing(method_name, *args, &block) ⇒ Object
Implement undefined setter with []= for FactoryBot to use without needing to define params to set.
-
#respond_to_missing?(method_name, *args) ⇒ Boolean
Used for setters that are not defined.
-
#save! ⇒ Self
Makes request, caching the response and returning self Used by FactoryBot.
-
#suburl=(url) ⇒ Object
Specify a url to add onto the base_url of the ExchangeHandler used.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Implement undefined setter with []= for FactoryBot to use without needing to define params to set
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/soaspec/exchange/request_builder.rb', line 34 def method_missing(method_name, *args, &block) set_value = args.first if method_name[-1] == '=' # A setter method getter_name = method_name[0..-2] if set_value.class < Exchange # This would be prerequisite exchange define_singleton_method(getter_name) { set_value } self[getter_name] = set_value.id if set_value.respond_to?(:id) else self[getter_name] = set_value end else super end end |
Instance Method Details
#[]=(key, value) ⇒ Object
Set a parameter request in the request body. Can be used to build a request over several steps (e.g Cucumber) Will be used with FactoryBot
25 26 27 28 |
# File 'lib/soaspec/exchange/request_builder.rb', line 25 def []=(key, value) @override_parameters[:body] ||= {} @override_parameters[:body][key] = value end |
#method=(method) ⇒ Object
Specify HTTP method to use. Default is :post
12 13 14 |
# File 'lib/soaspec/exchange/request_builder.rb', line 12 def method=(method) @override_parameters[:method] = method end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
Used for setters that are not defined
52 53 54 |
# File 'lib/soaspec/exchange/request_builder.rb', line 52 def respond_to_missing?(method_name, *args) method_name[-1] == '=' || super end |
#save! ⇒ Self
Makes request, caching the response and returning self Used by FactoryBot
59 60 61 62 63 |
# File 'lib/soaspec/exchange/request_builder.rb', line 59 def save! @retry_for_success = @fail_factory ? false : true call self end |
#suburl=(url) ⇒ Object
Specify a url to add onto the base_url of the ExchangeHandler used
6 7 8 |
# File 'lib/soaspec/exchange/request_builder.rb', line 6 def suburl=(url) @override_parameters[:suburl] = url end |