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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/soaspec/exchange/request_builder.rb', line 36 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
27 28 29 30 |
# File 'lib/soaspec/exchange/request_builder.rb', line 27 def []=(key, value) @override_parameters[:body] ||= {} @override_parameters[:body][key] = value end |
#method=(method) ⇒ Object
Specify HTTP method to use. Default is :post
14 15 16 |
# File 'lib/soaspec/exchange/request_builder.rb', line 14 def method=(method) @override_parameters[:method] = method end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
Used for setters that are not defined
54 55 56 |
# File 'lib/soaspec/exchange/request_builder.rb', line 54 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
61 62 63 64 65 66 67 68 |
# File 'lib/soaspec/exchange/request_builder.rb', line 61 def save! @retry_for_success = @fail_factory ? false : true previous_setting = Soaspec.log_warnings Soaspec.log_warnings = false # Don't log this warning as result of call not being used call Soaspec.log_warnings = previous_setting self end |
#suburl=(url) ⇒ Object
Specify a url to add onto the base_url of the ExchangeHandler used
8 9 10 |
# File 'lib/soaspec/exchange/request_builder.rb', line 8 def suburl=(url) @override_parameters[:suburl] = url end |