From 1c6483a499aa6374c2b11ade558e54f0873fd92e Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 29 Sep 2014 14:13:44 -0400 Subject: [PATCH] Simplify boolean attribute handling --- lib/linguist/lazy_blob.rb | 22 ++++++++++------------ test/test_repository.rb | 6 ------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 6b2e5e47..807312f9 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -30,29 +30,21 @@ module Linguist end def vendored? - if git_attributes['linguist-vendored'] - return result_for_key('linguist-vendored') + if attr = git_attributes['linguist-vendored'] + return boolean_attribute(attr) else return super end end def generated? - if git_attributes['linguist-generated'] - return result_for_key('linguist-generated') + if attr = git_attributes['linguist-generated'] + return boolean_attribute(attr) else return super end end - def result_for_key(keyname) - key = git_attributes[keyname] - if key == "false" || key.nil? - return false - else - return true - end - end def language return @language if defined?(@language) @@ -74,6 +66,12 @@ module Linguist end protected + + # Returns true if the attribute is present and not the string "false". + def boolean_attribute(attr) + attr != "false" + end + def load_blob! @data, @size = Rugged::Blob.to_buffer(repository, oid, MAX_SIZE) if @data.nil? end diff --git a/test/test_repository.rb b/test/test_repository.rb index dbd7e3a9..3401d655 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -81,8 +81,6 @@ class TestRepository < Test::Unit::TestCase # TODO: get rid of this (would like this to come from git data) file.stubs(:git_attributes).returns(git_attrs) - # check we're getting the correct assignment back from .gitattributes - assert file.result_for_key('linguist-generated') # overridden in .gitattributes assert file.generated? end @@ -98,8 +96,6 @@ class TestRepository < Test::Unit::TestCase # TODO: get rid of this (would like this to come from git data) override_vendored.stubs(:git_attributes).returns(git_attrs) - # check we're getting the correct assignment back from .gitattributes - assert override_vendored.result_for_key('linguist-vendored') # overridden .gitattributes assert override_vendored.vendored? end @@ -117,8 +113,6 @@ class TestRepository < Test::Unit::TestCase # TODO: get rid of this (would like this to come from git data) override_unvendored.stubs(:git_attributes).returns(git_attrs) - # check we're getting the correct assignment back from .gitattributes - assert !override_unvendored.result_for_key('linguist-vendored') # overridden .gitattributes assert !override_unvendored.vendored? end