Class: AssetTrip::LoadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/asset_trip/load_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths = []) ⇒ LoadPath

Returns a new instance of LoadPath.



6
7
8
# File 'lib/asset_trip/load_path.rb', line 6

def initialize(paths = [])
  @paths = paths.map { |path| Pathname.new(path) }
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



4
5
6
# File 'lib/asset_trip/load_path.rb', line 4

def paths
  @paths
end

Instance Method Details

#<<(path) ⇒ Object



15
16
17
# File 'lib/asset_trip/load_path.rb', line 15

def <<(path)
  @paths << Pathname.new(path)
end

#==(other) ⇒ Object



10
11
12
13
# File 'lib/asset_trip/load_path.rb', line 10

def ==(other)
  self.class == other.class &&
  @paths == other.paths
end

#resolve(file) ⇒ Object

TODO: Refactor

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/asset_trip/load_path.rb', line 20

def resolve(file)
  raise UnknownAssetError.new("Could not find #{file} in paths: #{@paths.inspect}") if file.nil?

  file_paths = @paths.map do |path|
    path.join(file).expand_path
  end

  result = file_paths.detect do |file_path|
    File.exist?(file_path)
  end

  if result
    return result
  else
    raise UnknownAssetError.new("Could not find #{file} in paths: #{@paths.inspect}")
  end
end