Class: Filament::TargetResolver
- Inherits:
-
Object
- Object
- Filament::TargetResolver
- Defined in:
- lib/filament/resolver.rb
Constant Summary collapse
- TARGET_REGEX =
format: //package_path:target_name
/^:([^:]+)$/
- PACKAGE_REGEX =
/^\/\/([^:]+)$/
- FULL_REGEX =
/^\/\/([^:]+):([^:]+)$/
Instance Method Summary collapse
-
#initialize(package) ⇒ TargetResolver
constructor
A new instance of TargetResolver.
- #resolve(uri) ⇒ Object
- #valid?(path) ⇒ Boolean (also: #valid_uri?)
Constructor Details
#initialize(package) ⇒ TargetResolver
Returns a new instance of TargetResolver.
46 47 48 49 |
# File 'lib/filament/resolver.rb', line 46 def initialize(package) @package = package @package_resolver = @package.package_resolver end |
Instance Method Details
#resolve(uri) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/filament/resolver.rb', line 56 def resolve(uri) package_path = nil target_name = nil if FULL_REGEX === uri package_path = $1 target_name = $2 end if TARGET_REGEX === uri package_path = nil target_name = $1 end if PACKAGE_REGEX === uri package_path = $1 target_name = nil end log "split_path(#{uri}) => package_path: #{package_path}, target_name: #{target_name}" if package_path.nil? package = @package log "using default package '#{@package.uri}' for target '#{target_name}'" else package = @package_resolver.resolve(package_path) raise "package '#{package_path}' not found in: #{@package_resolver.root_package_names.join(', ')}" if package.nil? end if target_name.nil? return package[package.name] else return package[target_name] end end |
#valid?(path) ⇒ Boolean Also known as: valid_uri?
51 52 53 |
# File 'lib/filament/resolver.rb', line 51 def valid?(path) return FULL_REGEX === path || TARGET_REGEX === path || PACKAGE_REGEX === path end |