Class: Hanami::Assets::BaseUrl Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/assets/base_url.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base URL

Since:

  • 2.1.0

Instance Method Summary collapse

Constructor Details

#initialize(url, prefix = nil) ⇒ BaseUrl

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a base URL

Parameters:

  • url (String)

    the URL

  • prefix (String, NilClass) (defaults to: nil)

    the prefix

Since:

  • 2.1.0



24
25
26
27
# File 'lib/hanami/assets/base_url.rb', line 24

def initialize(url, prefix = nil)
  @url = URI(url + prefix.to_s).to_s
  freeze
end

Instance Method Details

#crossorigin?(source) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the source is a cross origin

Parameters:

  • source (String)

    the source

Returns:

  • (Boolean)

    true if the source is a cross origin

Since:

  • 2.1.0



53
54
55
56
57
58
# File 'lib/hanami/assets/base_url.rb', line 53

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

#join(other) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Join the base URL with the given paths

Parameters:

  • other (String)

    the paths

Returns:

  • (String)

    the joined URL

Since:

  • 2.1.0



36
37
38
# File 'lib/hanami/assets/base_url.rb', line 36

def join(other)
  (url + other).to_s
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



42
43
44
# File 'lib/hanami/assets/base_url.rb', line 42

def to_s
  @url
end