Sha256: 6d24596f9b3d88eed3803da014752c5267974472382d3c8433f55cf31c3eeeec

Contents?: true

Size: 1009 Bytes

Versions: 2

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

require 'eac_git'
require 'eac_ruby_utils/core_ext'

module Avm
  module Sources
    class Base
      enable_simple_cache
      enable_listable
      lists.add_symbol :option, :parent
      common_constructor :path, :options, default: [{}] do
        self.path = path.to_pathname
        self.options = self.class.lists.option.hash_keys_validate!(options)
      end

      delegate :to_s, to: :path

      # @return [Avm::Sources::Base]
      def parent
        options[OPTION_PARENT]
      end

      # @return [Pathname]
      def relative_path
        return path if parent.blank?

        path.relative_path_from(parent.path)
      end

      # @return [Enumerable<Avm::Sources::Base>]
      def subs
        git_repo.subrepos
                .map { |subrepo| self.class.new(subrepo.subpath.expand_path(path), parent: self) }
      end

      private

      # @return [EacGit::Local]
      def git_repo_uncached
        ::EacGit::Local.new(path)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
avm-0.5.0 lib/avm/sources/base.rb
avm-tools-0.108.0 vendor/avm/lib/avm/sources/base.rb