Sha256: ba6b50fbbaac2b51652a883be58815bc0b6e1ba101d7963c82c65a0562abaee8

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Hanami
  class Assets
    # Base URL
    #
    # @since 2.1.0
    # @api private
    class BaseUrl
      # @since 2.1.0
      # @api private
      attr_reader :url
      private :url

      # Initialize a base URL
      #
      # @param url [String] the URL
      # @param prefix [String,NilClass] the prefix
      #
      # @since 2.1.0
      # @api private
      def initialize(url, prefix = nil)
        @url = URI(url + prefix.to_s).to_s
        freeze
      end

      # Join the base URL with the given paths
      #
      # @param other [String] the paths
      # @return [String] the joined URL
      #
      # @since 2.1.0
      # @api private
      def join(other)
        (url + other).to_s
      end

      # @since 2.1.0
      # @api private
      def to_s
        @url
      end

      # Check if the source is a cross origin
      #
      # @param source [String] the source
      # @return [Boolean] true if the source is a cross origin
      #
      # @since 2.1.0
      # @api private
      def crossorigin?(source)
        # TODO: review if this is the right way to check for cross origin
        return true if @url.empty?

        !source.start_with?(@url)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-assets-2.1.0.rc3 lib/hanami/assets/base_url.rb