Class: Linguist::LazyBlob

Inherits:
Object
  • Object
show all
Includes:
BlobHelper
Defined in:
lib/linguist/lazy_blob.rb

Constant Summary collapse

GIT_ATTR =
['linguist-language', 'linguist-vendored']
GIT_ATTR_OPTS =
{ :priority => [:index], :skip_system => true }
GIT_ATTR_FLAGS =
Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS)
MAX_SIZE =
128 * 1024

Constants included from BlobHelper

BlobHelper::MEGABYTE, BlobHelper::VendoredRegexp

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlobHelper

#_mime_type, #binary?, #binary_mime_type?, #colorize, #content_type, #csv?, #detect_encoding, #disposition, #encoding, #extname, #generated?, #high_ratio_of_long_lines?, #image?, #large?, #lexer, #likely_binary?, #lines, #loc, #mime_type, #pdf?, #ruby_encoding, #safe_to_colorize?, #sloc, #solid?, #text?, #viewable?

Constructor Details

#initialize(repo, oid, name, mode = nil) ⇒ LazyBlob

Returns a new instance of LazyBlob.



20
21
22
23
24
25
# File 'lib/linguist/lazy_blob.rb', line 20

def initialize(repo, oid, name, mode = nil)
  @repository = repo
  @oid = oid
  @name = name
  @mode = mode
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



18
19
20
# File 'lib/linguist/lazy_blob.rb', line 18

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/linguist/lazy_blob.rb', line 17

def name
  @name
end

#oidObject (readonly)

Returns the value of attribute oid.



16
17
18
# File 'lib/linguist/lazy_blob.rb', line 16

def oid
  @oid
end

#repositoryObject (readonly)

Returns the value of attribute repository.



15
16
17
# File 'lib/linguist/lazy_blob.rb', line 15

def repository
  @repository
end

Instance Method Details

#dataObject



50
51
52
53
# File 'lib/linguist/lazy_blob.rb', line 50

def data
  load_blob!
  @data
end

#git_attributesObject



27
28
29
30
# File 'lib/linguist/lazy_blob.rb', line 27

def git_attributes
  @git_attributes ||= repository.fetch_attributes(
    name, GIT_ATTR, GIT_ATTR_FLAGS)
end

#languageObject



40
41
42
43
44
45
46
47
48
# File 'lib/linguist/lazy_blob.rb', line 40

def language
  return @language if defined?(@language)

  @language = if lang = git_attributes['linguist-language']
    Language.find_by_name(lang)
  else
    super
  end
end

#sizeObject



55
56
57
58
# File 'lib/linguist/lazy_blob.rb', line 55

def size
  load_blob!
  @size
end

#vendored?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/linguist/lazy_blob.rb', line 32

def vendored?
  if attr = git_attributes['linguist-vendored']
    return boolean_attribute(attr)
  else
    return super
  end
end