Class: Juicer::Merger::DependencyResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/juicer/merger/dependency_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DependencyResolver

Constructor



7
8
9
10
# File 'lib/juicer/merger/dependency_resolver.rb', line 7

def initialize(options = {})
  @files = []
  @options = options
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



4
5
6
# File 'lib/juicer/merger/dependency_resolver.rb', line 4

def files
  @files
end

Instance Method Details

#resolve(file, &block) ⇒ Object

Resolve dependencies. This method accepts an optional block. The block will receive each file in succession. The file is included in the returned collection if the block is true for the given file. Without a block every found file is returned.



19
20
21
22
# File 'lib/juicer/merger/dependency_resolver.rb', line 19

def resolve(file, &block)
  @files = []
  _resolve(file, &block)
end

#resolve_path(path, reference) ⇒ Object

Resolves a path relative to another. If the path is absolute (ie it starts with a protocol or /) the :web_root options has to be set as well.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/juicer/merger/dependency_resolver.rb', line 29

def resolve_path(path, reference)
  # Absolute URL
  if path =~ %r{^(/|[a-z]+:)}
    if @options[:web_root].nil?
      msg = "Cannot resolve absolute path '#{path}' without web root option"
      raise ArgumentError.new(msg)
    end

    path.sub!(%r{^[a-z]+://[^/]+/}, '')
    return File.expand_path(File.join(@options[:web_root], path))
  end

  File.expand_path(File.join(File.dirname(reference), path))
end