lib/eac_templates/modules/ancestor.rb in eac_templates-0.5.1 vs lib/eac_templates/modules/ancestor.rb in eac_templates-0.7.0

- old
+ new

@@ -1,49 +1,35 @@ # frozen_string_literal: true require 'eac_ruby_utils/core_ext' require 'eac_templates/interface_methods' -require 'eac_templates/abstract/not_found_error' +require 'eac_templates/abstract/with_directory_file_methods' module EacTemplates module Modules class Ancestor + include ::EacTemplates::Abstract::WithDirectoryFileMethods + 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) + delegate(*::EacTemplates::InterfaceMethods::ALL + [:children_basenames], to: :sub_fs_object) - # @return [EacTemplates::Modules::Directory] - def directory - @directory ||= ::EacTemplates::Modules::Ancestor::Directory - .new(self, nil, nil, source_set: source_set) + def ancestor_path_for_search + self.class.path_for_search(ancestor) end - # @return [EacTemplates::Modules::File] - def file - @file ||= ::EacTemplates::Modules::Ancestor::File - .new(self, nil, nil, source_set: source_set) - end - # @return [Pathname] def path_for_search - r = self.class.path_for_search(ancestor) + r = ancestor_path_for_search 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 ::EacTemplates::Abstract::NotFoundError, "No template found: #{path_for_search}" end require_sub __FILE__ end end