Pass project to Blob
This commit is contained in:
parent
00e4ec55c3
commit
7f625f06d3
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue