Class: Interpol::Endpoint
- Inherits:
-
Object
- Object
- Interpol::Endpoint
- Includes:
- HashFetcher
- Defined in:
- lib/interpol/endpoint.rb
Overview
Represents an endpoint. Instances of this class are constructed based on the endpoint definitions in the YAML files.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#custom_metadata ⇒ Object
readonly
Returns the value of attribute custom_metadata.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #available_request_versions ⇒ Object
- #available_response_versions ⇒ Object
- #definitions ⇒ Object
- #find_definition!(version, message_type) ⇒ Object
- #find_definitions(version, message_type, &block) ⇒ Object
-
#initialize(endpoint_hash, configuration = Interpol.default_configuration) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #inspect ⇒ Object (also: #to_s)
- #route_matches?(path) ⇒ Boolean
Methods included from HashFetcher
Constructor Details
#initialize(endpoint_hash, configuration = Interpol.default_configuration) ⇒ Endpoint
Returns a new instance of Endpoint.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/interpol/endpoint.rb', line 74 def initialize(endpoint_hash, configuration = Interpol.default_configuration) @name = fetch_from(endpoint_hash, 'name') @route = fetch_from(endpoint_hash, 'route') @method = fetch_from(endpoint_hash, 'method').downcase.to_sym @configuration = configuration @custom_metadata = endpoint_hash.fetch('meta') { {} } @definitions_hash, @all_definitions = extract_definitions_from(endpoint_hash) validate_name! end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
72 73 74 |
# File 'lib/interpol/endpoint.rb', line 72 def configuration @configuration end |
#custom_metadata ⇒ Object (readonly)
Returns the value of attribute custom_metadata.
72 73 74 |
# File 'lib/interpol/endpoint.rb', line 72 def @custom_metadata end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
72 73 74 |
# File 'lib/interpol/endpoint.rb', line 72 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
72 73 74 |
# File 'lib/interpol/endpoint.rb', line 72 def name @name end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
72 73 74 |
# File 'lib/interpol/endpoint.rb', line 72 def route @route end |
Instance Method Details
#available_request_versions ⇒ Object
104 105 106 |
# File 'lib/interpol/endpoint.rb', line 104 def available_request_versions available_versions_matching &:request? end |
#available_response_versions ⇒ Object
108 109 110 |
# File 'lib/interpol/endpoint.rb', line 108 def available_response_versions available_versions_matching &:response? end |
#definitions ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/interpol/endpoint.rb', line 112 def definitions # sort all requests before all responses # sort higher version numbers before lower version numbers @sorted_definitions ||= @all_definitions.sort do |x, y| if x. == y. y.version <=> x.version else x. <=> y. end end end |
#find_definition!(version, message_type) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/interpol/endpoint.rb', line 87 def find_definition!(version, ) defs = find_definitions(version, ) do = "No definition found for #{name} endpoint for version #{version}" << " and message_type #{}" raise NoEndpointDefinitionFoundError.new() end return defs.first if defs.size == 1 raise MultipleEndpointDefinitionsFoundError, "#{defs.size} endpoint definitions " + "were found for #{name} / #{version} / #{}" end |
#find_definitions(version, message_type, &block) ⇒ Object
100 101 102 |
# File 'lib/interpol/endpoint.rb', line 100 def find_definitions(version, , &block) @definitions_hash.fetch([, version], &block) end |
#inspect ⇒ Object Also known as: to_s
128 129 130 |
# File 'lib/interpol/endpoint.rb', line 128 def inspect "#<#{self.class.name} #{method} #{route} (#{name})>" end |
#route_matches?(path) ⇒ Boolean
124 125 126 |
# File 'lib/interpol/endpoint.rb', line 124 def route_matches?(path) !!(path =~ route_regex) end |