Load Git Attributes for Linguist-specific overrides

This commit is contained in:
Vicent Marti
2014-09-10 16:59:43 +02:00
committed by The rugged tests are fragile
parent 16c1aa2845
commit 3d39e842ec
3 changed files with 43 additions and 1 deletions

View File

@@ -1,8 +1,13 @@
require 'linguist/blob_helper'
require 'linguist/language'
require 'rugged'
module Linguist
class LazyBlob
GIT_ATTR = ['linguist-ignore', 'linguist-lang']
GIT_ATTR_OPTS = { :priority => [:index], :skip_system => true }
GIT_ATTR_FLAGS = Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS)
include BlobHelper
MAX_SIZE = 128 * 1024
@@ -19,6 +24,25 @@ module Linguist
@mode = mode
end
def git_attributes
@git_attributes ||= repository.fetch_attributes(
name, GIT_ATTR, GIT_ATTR_FLAGS)
end
def ignored?
!!git_attributes['linguist-ignore']
end
def overriden_language
if lang = git_attributes['linguist-lang']
Language.find_by_name(lang)
end
end
def language
@language ||= (overriden_language || Language.detect(self))
end
def data
load_blob!
@data