Small code tweaks
This commit is contained in:
parent
0b3ff9c804
commit
b73b16798d
2 changed files with 18 additions and 16 deletions
|
@ -60,6 +60,9 @@ class Blob < SimpleDelegator
|
||||||
size && truncated?
|
size && truncated?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the size of the file that this blob represents. If this blob is an
|
||||||
|
# LFS pointer, this is the size of the file stored in LFS. Otherwise, this is
|
||||||
|
# the size of the blob itself.
|
||||||
def raw_size
|
def raw_size
|
||||||
if valid_lfs_pointer?
|
if valid_lfs_pointer?
|
||||||
lfs_size
|
lfs_size
|
||||||
|
@ -68,6 +71,10 @@ class Blob < SimpleDelegator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns whether the file that this blob represents is binary. If this blob is
|
||||||
|
# an LFS pointer, we assume the file stored in LFS is binary, unless a
|
||||||
|
# text-based rich blob viewer matched on the file's extension. Otherwise, this
|
||||||
|
# depends on the type of the blob itself.
|
||||||
def raw_binary?
|
def raw_binary?
|
||||||
if valid_lfs_pointer?
|
if valid_lfs_pointer?
|
||||||
if rich_viewer
|
if rich_viewer
|
||||||
|
@ -107,7 +114,7 @@ class Blob < SimpleDelegator
|
||||||
def rich_viewer
|
def rich_viewer
|
||||||
return @rich_viewer if defined?(@rich_viewer)
|
return @rich_viewer if defined?(@rich_viewer)
|
||||||
|
|
||||||
@rich_viewer ||= rich_viewer_class&.new(self)
|
@rich_viewer = rich_viewer_class&.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rendered_as_text?(ignore_errors: true)
|
def rendered_as_text?(ignore_errors: true)
|
||||||
|
@ -135,7 +142,10 @@ class Blob < SimpleDelegator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rich_viewers_classes
|
def rich_viewer_class
|
||||||
|
return if invalid_lfs_pointer? || empty?
|
||||||
|
|
||||||
|
classes =
|
||||||
if valid_lfs_pointer?
|
if valid_lfs_pointer?
|
||||||
RICH_VIEWERS
|
RICH_VIEWERS
|
||||||
elsif binary?
|
elsif binary?
|
||||||
|
@ -143,11 +153,7 @@ class Blob < SimpleDelegator
|
||||||
else # text
|
else # text
|
||||||
RICH_VIEWERS.select(&:text?)
|
RICH_VIEWERS.select(&:text?)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def rich_viewer_class
|
classes.find { |viewer_class| viewer_class.can_render?(self) }
|
||||||
return if invalid_lfs_pointer? || empty?
|
|
||||||
|
|
||||||
rich_viewers_classes.find { |viewer_class| viewer_class.can_render?(self) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -109,10 +109,6 @@ module Gitlab
|
||||||
@binary.nil? ? super : @binary == true
|
@binary.nil? ? super : @binary == true
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty?
|
|
||||||
!data || data == ''
|
|
||||||
end
|
|
||||||
|
|
||||||
def data
|
def data
|
||||||
encode! @data
|
encode! @data
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue