Class: Bemer::PathResolver
- Inherits:
-
Object
- Object
- Bemer::PathResolver
- Defined in:
- lib/bemer/path_resolver.rb
Instance Method Summary collapse
-
#initialize(view) ⇒ PathResolver
constructor
A new instance of PathResolver.
-
#resolve(name, partial = false) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(view) ⇒ PathResolver
Returns a new instance of PathResolver.
5 6 7 |
# File 'lib/bemer/path_resolver.rb', line 5 def initialize(view) @view = view end |
Instance Method Details
#resolve(name, partial = false) ⇒ Object
rubocop:disable Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bemer/path_resolver.rb', line 9 def resolve(name, partial = false) # rubocop:disable Metrics/AbcSize name = name.to_s virtual_dir = File.dirname(view.instance_variable_get(:@virtual_path)) dirs = [virtual_dir, File.dirname(name).delete('.')].reject(&:blank?) prefixes = [File.join(*dirs).to_s] format = File.extname(name).delete('.') unless partial basename = File.basename(name, '.*') = { formats: [format.to_sym] } if format return name unless view.lookup_context.exists?(basename, prefixes, partial, **.to_h) File.join(virtual_dir, name).to_s end |