Module: StubRequests::URI

Defined in:
lib/stub_requests/uri.rb,
lib/stub_requests/uri/scheme.rb,
lib/stub_requests/uri/suffix.rb,
lib/stub_requests/uri/builder.rb,
lib/stub_requests/uri/validator.rb

Overview

Module URI organizes all gem logic regarding URI

Author:

Since:

  • 0.1.0

Defined Under Namespace

Modules: Scheme, Suffix Classes: Builder, Validator

Constant Summary collapse

ROUTE_PARAM =

Returns A pattern for matching route parameters

Returns:

  • (Regexp)

    A pattern for matching route parameters

Since:

  • 0.1.2

%r{/:(\w+)/?}.freeze

Class Method Summary collapse

Class Method Details

.route_params(string) ⇒ Array<Symbol>

Extracts route parameters from a string

Parameters:

  • string (String)

    a regular string to scan for route parameters

Returns:

  • (Array<Symbol>)

    an array with all route parameter keys

Since:

  • 0.1.2



28
29
30
# File 'lib/stub_requests/uri.rb', line 28

def self.route_params(string)
  string.scan(ROUTE_PARAM).flatten.map(&:to_sym)
end

.safe_join(host, path) ⇒ String

Safely joins two string without any extra ///

Parameters:

  • host (String)

    the host of the URI

  • path (String)

    the path of the URI

Returns:

Since:

  • 0.1.2



40
41
42
# File 'lib/stub_requests/uri.rb', line 40

def self.safe_join(host, path)
  [host.chomp("/"), path.sub(%r{\A/}, "")].join("/")
end