Sha256: 41afbf655818bbf6b59a8f8142c4c35fa6a90c5e0355ee18b10db027ff69794d

Contents?: true

Size: 1.53 KB

Versions: 24

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/object/blank'
require 'eac_templates/sources/directory'
require 'eac_templates/sources/file'
require 'eac_templates/sources/internal_set'
require 'eac_templates/abstract/not_found_error'

module EacTemplates
  module Sources
    class Set
      class << self
        def default
          @default ||= new
        end
      end

      # @param subpath [Pathname]
      # @return [EacTemplates::Sources::Directory]
      def directory(subpath)
        ::EacTemplates::Sources::Directory.by_subpath(self, nil, subpath, source_set: self)
      end

      # @param subpath [Pathname]
      # @return [EacTemplates::Sources::Directory]
      def file(subpath)
        ::EacTemplates::Sources::File.by_subpath(self, nil, subpath, source_set: self)
      end

      def template(subpath, required = true)
        found_file = file(subpath)
        return found_file if found_file.found?

        found_directory = directory(subpath)
        return found_directory if found_directory.found?

        return nil unless required

        raise_template_not_found(subpath)
      end

      # @return [EacTemplates::Sources::InternalSet]
      def included_paths
        @included_paths ||= ::EacTemplates::Sources::InternalSet.new
      end

      private

      def raise_template_not_found(subpath)
        raise ::EacTemplates::Abstract::NotFoundError, 'Template not found for subpath ' \
          "\"#{subpath}\" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
eac_tools-0.76.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.75.2 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.75.1 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.75.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.74.1 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.74.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.73.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.72.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.70.1 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.70.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.69.1 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.69.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.68.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.67.1 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.67.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.66.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.65.1 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.65.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.64.0 sub/eac_templates/lib/eac_templates/sources/set.rb
eac_tools-0.63.0 sub/eac_templates/lib/eac_templates/sources/set.rb