Module: LHS::Record::Endpoints::ClassMethods
- Defined in:
- lib/lhs/concerns/record/endpoints.rb
Instance Method Summary collapse
-
#compute_url!(params) ⇒ Object
Computes the url from params by identifiying endpoint and compiles it if necessary.
-
#endpoint(url, options = nil) ⇒ Object
Adds the endpoint to the list of endpoints.
- #endpoints ⇒ Object
- #endpoints=(endpoints) ⇒ Object
-
#find_endpoint(params = {}) ⇒ Object
Find an endpoint based on the provided parameters.
- #for_url(url) ⇒ Object
-
#sanity_check(new_endpoint) ⇒ Object
Prevent clashing endpoints.
Instance Method Details
#compute_url!(params) ⇒ Object
Computes the url from params by identifiying endpoint and compiles it if necessary. Id in params is threaded in a special way.
62 63 64 65 66 67 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 62 def compute_url!(params) endpoint = find_endpoint(params) url = endpoint.compile(params) endpoint.remove_interpolated_params!(params) url end |
#endpoint(url, options = nil) ⇒ Object
Adds the endpoint to the list of endpoints.
24 25 26 27 28 29 30 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 24 def endpoint(url, = nil) endpoint = LHC::Endpoint.new(url, ) sanity_check(endpoint) endpoints.push(endpoint) LHS::Record::Endpoints.all ||= {} LHS::Record::Endpoints.all[url] = self end |
#endpoints ⇒ Object
15 16 17 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 15 def endpoints @endpoints ||= [] end |
#endpoints=(endpoints) ⇒ Object
19 20 21 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 19 def endpoints=(endpoints) @endpoints = endpoints end |
#find_endpoint(params = {}) ⇒ Object
Find an endpoint based on the provided parameters. If no parameters are provided it finds the base endpoint otherwise it finds the endpoint that matches the parameters best.
43 44 45 46 47 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 43 def find_endpoint(params = {}) endpoint = find_best_endpoint(params) if params && params.keys.count > 0 endpoint ||= find_base_endpoint endpoint end |
#for_url(url) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 32 def for_url(url) return unless url _template, record = LHS::Record::Endpoints.all.detect do |template, _| LHC::Endpoint.match?(url, template) end record end |
#sanity_check(new_endpoint) ⇒ Object
Prevent clashing endpoints.
50 51 52 53 54 55 56 57 |
# File 'lib/lhs/concerns/record/endpoints.rb', line 50 def sanity_check(new_endpoint) endpoints.each do |existing_endpoint| invalid = existing_endpoint.placeholders.sort == new_endpoint.placeholders.sort && existing_endpoint.url != new_endpoint.url next unless invalid fail "Clashing endpoints! Cannot differentiate between #{existing_endpoint.url} and #{new_endpoint.url}" end end |