Sha256: 272aba23ff8b7a1bcbd0fb1778ece4443af8abc374a78124ba4735e1ce2d6b25

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

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

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

          if grit_tree && grit_tree.respond_to?(:contents)
            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,
                submodule_url: (type == :submodule) ? entry.url(sha) : nil
              )
            end
          else
            []
          end
        end
      end

      def initialize(options)
        %w(id name path type mode commit_id submodule_url).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

9 entries across 9 versions & 1 rubygems

Version Path
gitlab_git-5.0.0 lib/gitlab_git/tree.rb
gitlab_git-4.1.0 lib/gitlab_git/tree.rb
gitlab_git-4.0.0 lib/gitlab_git/tree.rb
gitlab_git-4.0.0.pre lib/gitlab_git/tree.rb
gitlab_git-3.1.0 lib/gitlab_git/tree.rb
gitlab_git-3.0.1 lib/gitlab_git/tree.rb
gitlab_git-3.0.0 lib/gitlab_git/tree.rb
gitlab_git-3.0.0.rc2 lib/gitlab_git/tree.rb
gitlab_git-3.0.0.rc1 lib/gitlab_git/tree.rb