Sha256: 5621dbbbe9ed03e28f9f9f27fa98f94ee4df6c39ee285cd3a7faba1abd267f93

Contents?: true

Size: 770 Bytes

Versions: 3

Compression:

Stored size: 770 Bytes

Contents

# frozen_string_literal: true

require "pathname"

module Hanami
  class View
    # @api private
    class Path
      include Dry::Equalizer(:dir, :root)

      attr_reader :dir, :root

      def self.[](path)
        if path.is_a?(self)
          path
        else
          new(path)
        end
      end

      def initialize(dir, root: dir)
        @dir = Pathname(dir)
        @root = Pathname(root)
      end

      # Searches for a template using a wildcard for the engine extension
      def lookup(prefix, name, format)
        glob = dir.join(prefix, "#{name}.#{format}.*")
        Dir[glob].first
      end

      def chdir(dirname)
        self.class.new(dir.join(dirname), root: root)
      end

      def to_s
        dir.to_s
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-view-2.1.0.rc1 lib/hanami/view/path.rb
hanami-view-2.1.0.beta2 lib/hanami/view/path.rb
hanami-view-2.1.0.beta1 lib/hanami/view/path.rb