class RSpecApib::Element::TemplatedHref
Represents a templated href in api-elements (api-elements.readthedocs.io/en/latest/)
Public Class Methods
from_hash(hash, index:, parent:)
click to toggle source
Note this is not really a hash but the interface named it that early on as everything was a hash !! rubocop:disable Lint/UnusedMethodArgument
# File lib/rspec_apib/elements/templated_href.rb, line 10 def self.from_hash(hash, index:, parent:) new("templatedHref", nil, nil, hash, parent) end
host_from_parent(node)
click to toggle source
# File lib/rspec_apib/elements/templated_href.rb, line 35 def self.host_from_parent(node) return "" if node.nil? attrs = node.attributes return host_from_parent(node.parent) unless attrs && attrs["meta"] host_member = attrs["meta"].find do |member| member.is_a?(Member) && member.content.key?("HOST") end return host_from_parent(node.parent) unless host_member host_member.content["HOST"] end
Public Instance Methods
matches_path?(request)
click to toggle source
# File lib/rspec_apib/elements/templated_href.rb, line 18 def matches_path?(request) tpl = Addressable::Template.new(url) result = tpl.extract(request.url) !result.nil? end
path()
click to toggle source
# File lib/rspec_apib/elements/templated_href.rb, line 28 def path url_1 = Addressable::URI.parse(url) url_1.path, url_1.query, url_1.fragment = nil url_2 = Addressable::URI.parse(url) url_2.to_s.gsub(url_1.to_s, "") end
to_s()
click to toggle source
# File lib/rspec_apib/elements/templated_href.rb, line 14 def to_s content end
url()
click to toggle source
# File lib/rspec_apib/elements/templated_href.rb, line 24 def url @url ||= File.join(self.class.host_from_parent(parent), content) end