Class: OpenUSD::AssetResolver
- Inherits:
-
Object
- Object
- OpenUSD::AssetResolver
- Defined in:
- lib/openusd/asset_resolver.rb
Overview
Resolves authored asset paths relative to their containing layer.
Constant Summary collapse
- MISSING_POLICIES =
Supported unresolved-asset behaviors.
%i[error warn ignore].freeze
Instance Attribute Summary collapse
-
#missing_assets ⇒ Object
readonly
Returns the value of attribute missing_assets.
-
#search_paths ⇒ Object
readonly
Returns the value of attribute search_paths.
Instance Method Summary collapse
-
#initialize(search_paths: [], missing_assets: :error) ⇒ AssetResolver
constructor
A new instance of AssetResolver.
-
#resolve(asset_path, anchor: nil) ⇒ String?
Resolve an asset path, optionally anchored to a layer identifier.
Constructor Details
#initialize(search_paths: [], missing_assets: :error) ⇒ AssetResolver
Returns a new instance of AssetResolver.
13 14 15 16 17 18 19 |
# File 'lib/openusd/asset_resolver.rb', line 13 def initialize(search_paths: [], missing_assets: :error) @search_paths = search_paths.map { |path| File.(path) }.freeze @missing_assets = missing_assets.to_sym return if MISSING_POLICIES.include?(@missing_assets) raise ArgumentError, "invalid missing-assets policy: #{missing_assets.inspect}" end |
Instance Attribute Details
#missing_assets ⇒ Object (readonly)
Returns the value of attribute missing_assets.
11 12 13 |
# File 'lib/openusd/asset_resolver.rb', line 11 def missing_assets @missing_assets end |
#search_paths ⇒ Object (readonly)
Returns the value of attribute search_paths.
11 12 13 |
# File 'lib/openusd/asset_resolver.rb', line 11 def search_paths @search_paths end |
Instance Method Details
#resolve(asset_path, anchor: nil) ⇒ String?
Resolve an asset path, optionally anchored to a layer identifier.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openusd/asset_resolver.rb', line 23 def resolve(asset_path, anchor: nil) = asset_path.is_a?(AssetPath) ? asset_path.path : asset_path.to_s return resolve_package_asset(, anchor) if package_uri?(anchor) return File.(anchor) if .empty? && anchor resolved = candidates(, anchor).find { |candidate| File.file?(candidate) } return resolved if resolved missing(, anchor) end |