Class: Soaspec::ExchangeHandler
- Inherits:
-
Object
- Object
- Soaspec::ExchangeHandler
- Extended by:
- HandlerAccessors
- Defined in:
- lib/soaspec/exchange_handlers/exchange_handler.rb
Overview
Inherit this for a class describing how to implement a particular exchange. Has basic methods common for methods defining RSpec tests in YAML
Direct Known Subclasses
Instance Attribute Summary collapse
-
#template_name ⇒ Object
Retrieve the name of the template file to be used in the API request.
Instance Method Summary collapse
-
#default_hash=(hash) ⇒ Object
Set the default hash representing data to be used in making a request This will set the @request_option instance variable too.
-
#elements ⇒ Object
Explicitly defined elements for which a path has been predefined.
-
#expected_mandatory_elements ⇒ Array
Will be used in ‘success_scenarios’ shared examples.
-
#expected_mandatory_json_values ⇒ Hash
Change this through ‘mandatory_json_values’ method to specify json results that must be present in the response Will be used in ‘success_scenarios’ shared examples.
-
#expected_mandatory_xpath_values ⇒ Hash
Change this through ‘mandatory_xpath_values’ method to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples.
-
#initialize(name = self.class.to_s, options = {}) ⇒ ExchangeHandler
constructor
Set instance variable name.
-
#set_remove_key(hash, key) ⇒ Object
Set instance variable and remove it from Hash.
-
#store(name, value) ⇒ Object
Stores a value in a method that can be accessed by the provided name.
-
#to_s ⇒ String
Sets api handler variable globally.
-
#use ⇒ Self
Set Api handler used by Exchange class to this handler.
Methods included from HandlerAccessors
attribute, element, mandatory_elements, mandatory_json_values, mandatory_xpath_values
Constructor Details
#initialize(name = self.class.to_s, options = {}) ⇒ ExchangeHandler
Set instance variable name
29 30 31 32 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 29 def initialize(name = self.class.to_s, = {}) use @name = name end |
Instance Attribute Details
#template_name ⇒ Object
Retrieve the name of the template file to be used in the API request
12 13 14 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 12 def template_name @template_name end |
Instance Method Details
#default_hash=(hash) ⇒ Object
Set the default hash representing data to be used in making a request This will set the @request_option instance variable too
21 22 23 24 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 21 def default_hash=(hash) @request_option = :hash @default_hash = Soaspec.always_use_keys? ? hash.transform_keys_to_symbols : hash end |
#elements ⇒ Object
Explicitly defined elements for which a path has been predefined
15 16 17 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 15 def elements public_methods.select { |i| i[/__custom_path_.+/] } end |
#expected_mandatory_elements ⇒ Array
Will be used in ‘success_scenarios’ shared examples. Set though ‘mandatory_elements’ method
59 60 61 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 59 def expected_mandatory_elements [] end |
#expected_mandatory_json_values ⇒ Hash
Change this through ‘mandatory_json_values’ method to specify json results that must be present in the response Will be used in ‘success_scenarios’ shared examples
73 74 75 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 73 def expected_mandatory_json_values {} end |
#expected_mandatory_xpath_values ⇒ Hash
Change this through ‘mandatory_xpath_values’ method to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples
66 67 68 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 66 def expected_mandatory_xpath_values {} end |
#set_remove_key(hash, key) ⇒ Object
Set instance variable and remove it from Hash
87 88 89 90 91 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 87 def set_remove_key(hash, key) return unless hash.key? key __send__("#{key}=", hash[key]) hash.delete key end |
#store(name, value) ⇒ Object
Stores a value in a method that can be accessed by the provided name
80 81 82 83 84 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 80 def store(name, value) define_singleton_method('__stored_val__' + name.to_s) do value end end |
#to_s ⇒ String
Sets api handler variable globally. This is used in ‘Exchange’ class
43 44 45 46 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 43 def to_s use @name.to_s end |
#use ⇒ Self
Set Api handler used by Exchange class to this handler
36 37 38 39 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 36 def use Soaspec.api_handler = self self end |