mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Simplify boolean attribute handling
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user