Sha256: ca8edbd6f6f8ad937f04f8a8ae0cddc74585910e102d2d0e36cfab8ed9dfe815

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_templates/interface_methods'

module EacTemplates
  module Modules
    class Ancestor
      class << self
        # @param a_module [Module]
        # @return [Pathname]
        def path_for_search(a_module)
          a_module.name.underscore.to_pathname
        end
      end

      common_constructor :base, :ancestor
      delegate :subpath, :source_set, to: :base
      delegate(*::EacTemplates::InterfaceMethods::ALL, to: :source_object)

      # @return [EacTemplates::Modules::Directory]
      def directory
        ::EacTemplates::Modules::Ancestor::Directory.new(self)
      end

      # @return [EacTemplates::Modules::File]
      def file
        @file ||= ::EacTemplates::Modules::Ancestor::File.new(self)
      end

      # @return [Pathname]
      def path_for_search
        r = self.class.path_for_search(ancestor)
        subpath.if_present(r) { |v| r.join(v) }
      end

      # @return [EacTemplates::Modules::Ancestor::FsObject]
      def source_object
        return file if file.found?
        return directory if directory.found?

        raise "No template found: #{path_for_search}"
      end

      require_sub __FILE__
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
eac_tools-0.61.0 sub/eac_templates/lib/eac_templates/modules/ancestor.rb
eac_templates-0.4.0 lib/eac_templates/modules/ancestor.rb
eac_tools-0.60.3 sub/eac_templates/lib/eac_templates/modules/ancestor.rb