Class: Hanami::Assets::Asset

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

Overview

Represents a single front end asset.

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, base_url:, sri: nil) ⇒ Asset

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.

Returns a new instance of Asset.

Since:

  • 2.1.0



44
45
46
47
48
# File 'lib/hanami/assets/asset.rb', line 44

def initialize(path:, base_url:, sri: nil)
  @path = path
  @base_url = base_url
  @sri = sri
end

Instance Attribute Details

#pathString (readonly)

Returns the asset’s absolute URL path.

Examples:

Asset from local dev server

asset.path # => "/assets/app.js"

Deployed asset with fingerprinted name

asset.path # => "/assets/app-28a6b886de2372ee3922fcaf3f78f2d8.js"

Returns:

  • (String)

Since:

  • 2.1.0



27
28
29
# File 'lib/hanami/assets/asset.rb', line 27

def path
  @path
end

#sriString? (readonly) Also known as: subresource_integrity_value

Returns the asset’s subresource integrity value, or nil if none is available.

Returns:

  • (String, nil)

Since:

  • 2.1.0



40
41
42
# File 'lib/hanami/assets/asset.rb', line 40

def sri
  @sri
end

Instance Method Details

#to_sString

Returns the asset’s full URL

Returns:

  • (String)

See Also:

Since:

  • 2.1.0



78
79
80
# File 'lib/hanami/assets/asset.rb', line 78

def to_s
  url
end

#urlString

Returns the asset’s full URL.

Examples:

Asset from local dev server

asset.path # => "https://example.com/assets/app.js"

Deployed asset with fingerprinted name

asset.path # => "https://example.com/assets/app-28a6b886de2372ee3922fcaf3f78f2d8.js"

Returns:

  • (String)

Since:

  • 2.1.0



66
67
68
# File 'lib/hanami/assets/asset.rb', line 66

def url
  base_url.join(path)
end