class LHC::Endpoint
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/lhc/endpoint.rbs class LHC::Endpoint def self.placeholders: () -> Array[] def compile: (Hash params) -> String def initialize: (String url, ?nil options) -> void def placeholders: () -> Array[] def remove_interpolated_params!: (Hash? params) -> Hash def uri: () -> Addressable::Template end
The url can also be an url-template (tools.ietf.org/html/rfc6570).
An endpoint is an url that leads to a backend resource.
def self.match?(url, template)
Returns true if concrete url is covered by the template
Compares a concrete url with a template
def self.match?(url, template) new(template).match?(url) end
def self.placeholders(template)
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.placeholders: () ->
This signature was generated using 70 samples from 4 applications.
Returns all placeholders found in the url-template.
def self.placeholders(template) new(template).placeholders end
def self.values_as_params(template, url)
Extracts the values from url and
def self.values_as_params(template, url) raise("#{url} does not match the template: #{template}") if !match?(url, template) new(template).values_as_params(url) end
def compile(params)
Experimental RBS support (using type sampling data from the type_fusion
project).
type LHC__Endpoint_compile_params = sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | return_value | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | Array | String | Array | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | return_value | Array | Array | String | Array | String | Array | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | Array | String | Array | | Array | String | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | String | return_value | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | Array | String | Array | | return_value | Array | | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | String | Array | String | String | String | Array | String | String | String | Array | String | String | String | Array | String | String | String | return_value | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | String | return_value | Array | | sample | gem_name | String | gem_version | String | receiver | NilClass | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | return_value | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | return_value | Array | String | Array | String | Array | | String | String | String | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | String | Array | String | String | String | Array | String | String | String | return_value | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | return_value | Array | | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | Array | String | Array | | Array | String | String | String | Array | String | String | String | Array | String | String | String | return_value | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | | return_value | Array | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | sample | gem_name | String | gem_version | String | receiver | String | method_name | String | application_name | String | location | String | type_fusion_version | String | parameters | Array | String | String | Array | String | Array | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | Array | String | String | return_value | String def compile: (LHC__Endpoint_compile_params params) -> String
This signature was generated using 39 samples from 4 applications.
def compile(params) context = LHC.config.placeholders.deep_dup context.merge!(params) if params.is_a?(Hash) expanded = uri.partial_expand(context) if expanded.variables.empty? expanded.pattern else raise("Compilation incomplete. Unable to find value for #{expanded.variables.join(', ')}.") end end
def find_value(name, mapping)
def find_value(name, mapping) context = LHC.config.placeholders.deep_dup context.merge!(mapping) context[name] end
def initialize(url, options = nil)
Experimental RBS support (using type sampling data from the type_fusion
project).
def initialize: (String url, ?nil options) -> void
This signature was generated using 26 samples from 3 applications.
def initialize(url, options = nil) self.url = url self.options = options end
def match?(url)
Returns true if concrete url is covered by the template
Compares a concrete url with a template
def match?(url) return true if url == uri.pattern match_data = match_data(url) return false if match_data.nil? first = match_data.values.first last = match_data.values.last url_format = File.extname(url) # eliminate false positives in form: # http://host/feedbacks matches {+service}/{entry_id}/feedbacks (service: http:/, entry_id: host) first&.match(%{https?:/$}).nil? && # eliminates false positives in form: # http://host/entries/123.json matches {+service}/entries/{id} (service: http://host, id: 123.json) (url_format.blank? || !last&.ends_with?(url_format)) end
def match_data(url)
def match_data(url) parsed = URI.parse(url) parsed.query = parsed.fragment = nil uri.match(parsed) rescue URI::InvalidURIError nil end
def options
def options @options.deep_dup end
def placeholders
Experimental RBS support (using type sampling data from the type_fusion
project).
def placeholders: () ->
This signature was generated using 70 samples from 4 applications.
Returns all placeholders found in the url-template.
def placeholders uri.variables.sort.map(&:to_sym) end
def remove_interpolated_params!(params)
Experimental RBS support (using type sampling data from the type_fusion
project).
def remove_interpolated_params!: ([]? params) ->
This signature was generated using 50 samples from 3 applications.
Removes keys from provided params hash
def remove_interpolated_params!(params) params ||= {} removed = params.slice(*placeholders) params.except!(*placeholders) removed end
def uri
Experimental RBS support (using type sampling data from the type_fusion
project).
def uri: () -> Addressable::Template
This signature was generated using 111 samples from 5 applications.
def uri @uri ||= Addressable::Template.new(url) end
def values_as_params(url)
Extracts the values from url and
def values_as_params(url) match_data = match_data(url) return if match_data.nil? Hash[match_data.variables.map(&:to_sym).zip(match_data.values)] end