diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-13 11:59:52 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 12:23:26 -0500 |
commit | 7f625f06d333cbe3846081924a3e7016b2846ae0 (patch) | |
tree | 5b70dc5cec031869ddb84f7bceb2c0aedb3dfaf9 /app/models | |
parent | 00e4ec55c3b8757e6d5fb8bf3176dd7e20966b3a (diff) | |
download | gitlab-ce-7f625f06d333cbe3846081924a3e7016b2846ae0.tar.gz |
Pass project to Blob
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob.rb | 12 | ||||
-rw-r--r-- | app/models/commit.rb | 2 | ||||
-rw-r--r-- | app/models/repository.rb | 2 |
3 files changed, 12 insertions, 4 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 55872acef51..c6315a6789f 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -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. diff --git a/app/models/commit.rb b/app/models/commit.rb index 8b8b3f00202..bb4cb8efd15 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -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] diff --git a/app/models/repository.rb b/app/models/repository.rb index e74edb8e6f7..d02aea49689 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 |