Class: Filament::PackageResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/filament/resolver.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_resolver = nil) ⇒ PackageResolver

Returns a new instance of PackageResolver.



3
4
5
6
# File 'lib/filament/resolver.rb', line 3

def initialize(parent_resolver=nil)
  @parent = parent_resolver
  @root_packages = []
end

Instance Method Details

#<<(root_package) ⇒ Object



8
9
10
# File 'lib/filament/resolver.rb', line 8

def <<(root_package)
  @root_packages << root_package unless root_package.nil?
end

#resolve(uri) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/filament/resolver.rb', line 12

def resolve(uri)
  uri = uri.gsub(/^\/\//, '')
  
  @root_packages.each do |pkg|
    subpkg = pkg.subpackage(uri)
    return subpkg unless subpkg.nil?
  end
  
  if @parent.nil?
    return nil
  else
    return @parent.resolve(uri)
  end
end

#root_package_namesObject



35
36
37
# File 'lib/filament/resolver.rb', line 35

def root_package_names
  root_packages.collect { |p| p.full_name }
end

#root_packagesObject



27
28
29
30
31
32
33
# File 'lib/filament/resolver.rb', line 27

def root_packages
  if @parent.nil?
    return @root_packages
  else
    return @root_packages + @parent.root_packages
  end
end