Sha256: ca70aa5f79b16861ac19a33bc22da3bc8876cb9c6f868441068b23ff09cc066e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Gitlab
  module Git
    class Tree
      attr_accessor :id, :name, :path, :type, :mode, :commit_id

      class << self
        def where(repository, sha, path = '/')
          commit = Commit.find(repository, sha)
          grit_tree = commit.tree / path

          if grit_tree
            grit_tree.contents.map do |entry|
              type = entry.class.to_s.split("::").last.downcase.to_sym

              Tree.new(
                id: entry.id,
                name: entry.name,
                type: type,
                mode: entry.mode,
                path: path == '/' ? entry.name : File.join(path, entry.name),
                commit_id: sha,
              )
            end
          else
            []
          end
        end
      end

      def initialize(options)
        %w(id name path type mode commit_id).each do |key|
          self.send("#{key}=", options[key.to_sym])
        end
      end

      def dir?
        type == :tree
      end

      def file?
        type == :blob
      end

      def submodule?
        type == :submodule
      end

      def readme?
        name =~ /^readme/i
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitlab_git-3.0.0.pre lib/gitlab_git/tree.rb