Pass project to Blob

This commit is contained in:
Douwe Maan 2017-04-13 11:59:52 -05:00
parent 00e4ec55c3
commit 7f625f06d3
4 changed files with 13 additions and 5 deletions

View File

@ -96,7 +96,7 @@ class Projects::BlobController < Projects::ApplicationController
private
def blob
@blob ||= Blob.decorate(@repository.blob_at(@commit.id, @path))
@blob ||= Blob.decorate(@repository.blob_at(@commit.id, @path), @project)
if @blob
@blob

View File

@ -6,6 +6,8 @@ class Blob < SimpleDelegator
# The maximum size of an SVG that can be displayed.
MAXIMUM_SVG_SIZE = 2.megabytes
attr_reader :project
# Wrap a Gitlab::Git::Blob object, or return nil when given nil
#
# This method prevents the decorated object from evaluating to "truthy" when
@ -16,10 +18,16 @@ class Blob < SimpleDelegator
#
# blob = Blob.decorate(nil)
# puts "truthy" if blob # No output
def self.decorate(blob)
def self.decorate(blob, project)
return if blob.nil?
new(blob)
new(blob, project)
end
def initialize(blob, project)
@project = project
super(blob)
end
# Returns the data of the blob.

View File

@ -316,7 +316,7 @@ class Commit
def uri_type(path)
entry = @raw.tree.path(path)
if entry[:type] == :blob
blob = ::Blob.decorate(Gitlab::Git::Blob.new(name: entry[:name]))
blob = ::Blob.decorate(Gitlab::Git::Blob.new(name: entry[:name]), @project)
blob.image? || blob.video? ? :raw : :blob
else
entry[:type]

View File

@ -450,7 +450,7 @@ class Repository
def blob_at(sha, path)
unless Gitlab::Git.blank_ref?(sha)
Blob.decorate(Gitlab::Git::Blob.find(self, sha, path))
Blob.decorate(Gitlab::Git::Blob.find(self, sha, path), project)
end
rescue Gitlab::Git::Repository::NoRepository
nil