Commit 7f625f06 authored by Douwe Maan's avatar Douwe Maan

Pass project to Blob

parent 00e4ec55
...@@ -96,7 +96,7 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -96,7 +96,7 @@ class Projects::BlobController < Projects::ApplicationController
private private
def blob def blob
@blob ||= Blob.decorate(@repository.blob_at(@commit.id, @path)) @blob ||= Blob.decorate(@repository.blob_at(@commit.id, @path), @project)
if @blob if @blob
@blob @blob
......
...@@ -6,6 +6,8 @@ class Blob < SimpleDelegator ...@@ -6,6 +6,8 @@ class Blob < SimpleDelegator
# The maximum size of an SVG that can be displayed. # The maximum size of an SVG that can be displayed.
MAXIMUM_SVG_SIZE = 2.megabytes MAXIMUM_SVG_SIZE = 2.megabytes
attr_reader :project
# Wrap a Gitlab::Git::Blob object, or return nil when given nil # Wrap a Gitlab::Git::Blob object, or return nil when given nil
# #
# This method prevents the decorated object from evaluating to "truthy" when # This method prevents the decorated object from evaluating to "truthy" when
...@@ -16,10 +18,16 @@ class Blob < SimpleDelegator ...@@ -16,10 +18,16 @@ class Blob < SimpleDelegator
# #
# blob = Blob.decorate(nil) # blob = Blob.decorate(nil)
# puts "truthy" if blob # No output # puts "truthy" if blob # No output
def self.decorate(blob) def self.decorate(blob, project)
return if blob.nil? return if blob.nil?
new(blob) new(blob, project)
end
def initialize(blob, project)
@project = project
super(blob)
end end
# Returns the data of the blob. # Returns the data of the blob.
......
...@@ -316,7 +316,7 @@ class Commit ...@@ -316,7 +316,7 @@ class Commit
def uri_type(path) def uri_type(path)
entry = @raw.tree.path(path) entry = @raw.tree.path(path)
if entry[:type] == :blob 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 blob.image? || blob.video? ? :raw : :blob
else else
entry[:type] entry[:type]
......
...@@ -450,7 +450,7 @@ class Repository ...@@ -450,7 +450,7 @@ class Repository
def blob_at(sha, path) def blob_at(sha, path)
unless Gitlab::Git.blank_ref?(sha) 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 end
rescue Gitlab::Git::Repository::NoRepository rescue Gitlab::Git::Repository::NoRepository
nil nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment