class ApiBlueprint::Url

Attributes

base[R]
custom[R]

Public Class Methods

new(base = "", custom = "") click to toggle source
# File lib/api-blueprint/url.rb, line 5
def initialize(base = "", custom = "")
  self.base = base
  self.custom = custom
end

Public Instance Methods

base=(str) click to toggle source
# File lib/api-blueprint/url.rb, line 10
def base=(str)
  @base = Addressable::URI.parse str
end
custom=(str) click to toggle source
# File lib/api-blueprint/url.rb, line 14
def custom=(str)
  @custom = Addressable::URI.parse str
end
to_s() click to toggle source
# File lib/api-blueprint/url.rb, line 18
def to_s
  if base.path.present? && custom.path.present? && !custom.host.present?
    # Join paths in a permissive way which handles extra slashes gracefully and returns
    # a string which Addressable can handle when joining with other paths
    paths = [base.path, custom.path].compact.map { |path| path.gsub(%r{^/*(.*?)/*$}, '\1') }.join("/")
    Addressable::URI.join(base.site, paths).to_s
  else
    base.join(custom).to_s
  end
end