Class: Blob

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/models/blob.rb

Overview

Blob is a Rails-specific wrapper around Gitlab::Git::Blob objects

Constant Summary collapse

CACHE_TIME =

Cache raw blobs referred to by a (mutable) ref for 1 minute

60
CACHE_TIME_IMMUTABLE =

Cache blobs referred to by an immutable reference for 1 hour

3600

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decorate(blob) ⇒ Object

Wrap a Gitlab::Git::Blob object, or return nil when given nil

This method prevents the decorated object from evaluating to “truthy” when given a nil value. For example:

blob = Blob.new(nil)
puts "truthy" if blob # => "truthy"

blob = Blob.decorate(nil)
puts "truthy" if blob # No output

16
17
18
19
20
# File 'app/models/blob.rb', line 16

def self.decorate(blob)
  return if blob.nil?

  new(blob)
end

Instance Method Details

#no_highlighting?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'app/models/blob.rb', line 22

def no_highlighting?
  size && size > 1.megabyte
end

#only_display_raw?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'app/models/blob.rb', line 26

def only_display_raw?
  size && size > 5.megabytes
end

#svg?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'app/models/blob.rb', line 30

def svg?
  text? && language && language.name == 'SVG'
end

#to_partial_pathObject


34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/blob.rb', line 34

def to_partial_path
  if lfs_pointer?
    'download'
  elsif image? || svg?
    'image'
  elsif text?
    'text'
  else
    'download'
  end
end