Class: Brut::FrontEnd::InlineSvgLocator
- Inherits:
-
Object
- Object
- Brut::FrontEnd::InlineSvgLocator
- Defined in:
- lib/brut/front_end/inline_svg_locator.rb
Instance Method Summary collapse
-
#initialize(paths:) ⇒ InlineSvgLocator
constructor
A new instance of InlineSvgLocator.
-
#locate(base_name) ⇒ Object
Constructor Details
#initialize(paths:) ⇒ InlineSvgLocator
Returns a new instance of InlineSvgLocator.
2 3 4 |
# File 'lib/brut/front_end/inline_svg_locator.rb', line 2 def initialize(paths:) @paths = Array(paths).map { |path| Pathname(path) } end |
Instance Method Details
#locate(base_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/brut/front_end/inline_svg_locator.rb', line 6 def locate(base_name) paths_to_try = @paths.map { |path| path / "#{base_name}.svg" } paths_found = paths_to_try.select { |path| path.exist? } if paths_found.empty? raise "Could not locate SVG for #{base_name}. Tried: #{paths_to_try.map(&:to_s).join(', ')}" end if paths_found.length > 1 raise "Found more than one valid path for #{base_name}. You must rename your files to disambiguate them. These paths were all found: #{paths_found.map(&:to_s).join(', ')}" end return paths_found[0] end |