Sha256: 3c15e33f4781a8125f1a4ff713ed591bee2c9e54b38c317affc4a48027b4e273

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

module Gitlab
  module Git
    class Tree
      attr_accessor :repository, :sha, :path, :ref, :raw_tree, :id

      def initialize(repository, sha, ref = nil, path = nil)
        @repository, @sha, @ref, @path = repository, sha, ref, path

        @path = nil if !@path || @path == ''

        # Load tree from repository
        @commit = Gitlab::Git::Commit.find(@repository, @sha)
        @raw_tree = @repository.tree(@commit, @path)
      end

      def exists?
        raw_tree
      end

      def empty?
        trees.empty? && blobs.empty?
      end

      def trees
        entries.select { |t| t.is_a?(Grit::Tree) }
      end

      def blobs
        entries.select { |t| t.is_a?(Grit::Blob) }
      end

      def submodules
        entries.select { |t| t.is_a?(Grit::Submodule) }
      end

      def is_blob?
        raw_tree.is_a?(Grit::Blob)
      end

      def up_dir?
        path && path != ''
      end

      def readme
        @readme ||= blobs.find { |c| c.name =~ /^readme/i }
      end

      protected

      def entries
        raw_tree.contents
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gitlab_git-2.3.1 lib/gitlab_git/tree.rb
gitlab_git-2.3.0 lib/gitlab_git/tree.rb
gitlab_git-2.2.0 lib/gitlab_git/tree.rb
gitlab_git-2.1.1 lib/gitlab_git/tree.rb
gitlab_git-2.1.0 lib/gitlab_git/tree.rb
gitlab_git-2.0.1 lib/gitlab_git/tree.rb
gitlab_git-2.0.0 lib/gitlab_git/tree.rb
gitlab_git-2.0.0.pre2 lib/gitlab_git/tree.rb
gitlab_git-2.0.0.beta lib/gitlab_git/tree.rb
gitlab_git-2.0.0.pre lib/gitlab_git/tree.rb