Sha256: b9628f96457c6057be73861216b3c2927d62696d6b3d1782f92719039f962e7d

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

#
# Abstraction over WebMock to reduce duplication
#
# @author Mikael Henriksson <mikael@zoolutions.se>
# @since 0.1.0
#
module StubRequests
  #
  # Module URI organizes all gem logic regarding URI
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  # @since 0.1.2
  #
  module URI
    #
    # @return [Regexp] A pattern for matching route parameters
    ROUTE_PARAM = %r{/:(\w+)/?}.freeze

    #
    # Extracts route parameters from a string
    #
    # @param [String] string a regular string to scan for route parameters
    #
    # @return [Array<Symbol>] an array with all route parameter keys
    #
    def self.route_params(string)
      string.scan(ROUTE_PARAM).flatten.map(&:to_sym)
    end

    #
    # Safely joins two string without any extra ///
    #
    # @param [String] host the host of the URI
    # @param [String] path the path of the URI
    #
    # @return [String] the full URI
    #
    def self.safe_join(host, path)
      [host.chomp("/"), path.sub(%r{\A/}, "")].join("/")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stub_requests-0.1.11 lib/stub_requests/uri.rb
stub_requests-0.1.10 lib/stub_requests/uri.rb