Class: Hanami::Assets::Asset Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/assets/asset.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.

Requested asset

Since:

  • 0.8.0

Constant Summary collapse

PUBLIC_DIRECTORY =

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

Since:

  • 0.8.0

Hanami.public_directory.join('**', '*').to_s.freeze
URL_SEPARATOR =

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

Since:

  • 0.8.0

'/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources, path) ⇒ 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:

  • 0.8.0



33
34
35
36
37
38
39
40
# File 'lib/hanami/assets/asset.rb', line 33

def initialize(sources, path)
  @path            = path
  @prefix, @config = sources.find { |p, _| path.start_with?(p) }

  if @prefix && @config
    @original = @config.sources.find(@path.sub(@prefix, ''))
  end
end

Instance Attribute Details

#configObject (readonly)

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:

  • 0.8.0



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

def config
  @config
end

#originalObject (readonly)

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:

  • 0.8.0



29
30
31
# File 'lib/hanami/assets/asset.rb', line 29

def original
  @original
end

#pathObject (readonly)

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:

  • 0.8.0



21
22
23
# File 'lib/hanami/assets/asset.rb', line 21

def path
  @path
end

Instance Method Details

#exist?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.

Returns:

  • (Boolean)

Since:

  • 0.8.0



50
51
52
53
54
55
56
57
58
59
# File 'lib/hanami/assets/asset.rb', line 50

def exist?
  return true unless original.nil?

  file_path = path.tr(URL_SEPARATOR, ::File::SEPARATOR)
  destination = find_asset do |a|
    a.end_with?(file_path)
  end

  !destination.nil?
end

#precompile?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.

Returns:

  • (Boolean)

Since:

  • 0.8.0



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

def precompile?
  original && config
end