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


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

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


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

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


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

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


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

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.

Since:

  • 0.8.0


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

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.

Since:

  • 0.8.0


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

def precompile?
  original && config
end