mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Use the original FileBlob path for filesystem access
FileBlob now remembers the full path that was passed to its constructor, and uses that for performing filesystem access. FileBlob#path continues to return a relative path as before. This ensures that you can call methods like #size and #mode on FileBlobs with relative paths, regardless of the current working directory.
This commit is contained in:
		@@ -14,6 +14,7 @@ module Linguist
 | 
				
			|||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns a FileBlob.
 | 
					    # Returns a FileBlob.
 | 
				
			||||||
    def initialize(path, base_path = nil)
 | 
					    def initialize(path, base_path = nil)
 | 
				
			||||||
 | 
					      @fullpath = path
 | 
				
			||||||
      @path = base_path ? path.sub("#{base_path}/", '') : path
 | 
					      @path = base_path ? path.sub("#{base_path}/", '') : path
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,28 +36,28 @@ module Linguist
 | 
				
			|||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns a String like '100644'
 | 
					    # Returns a String like '100644'
 | 
				
			||||||
    def mode
 | 
					    def mode
 | 
				
			||||||
      File.stat(@path).mode.to_s(8)
 | 
					      File.stat(@fullpath).mode.to_s(8)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Public: File name
 | 
					    # Public: File name
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns a String
 | 
					    # Returns a String
 | 
				
			||||||
    def name
 | 
					    def name
 | 
				
			||||||
      File.basename(path)
 | 
					      File.basename(@fullpath)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Public: Read file contents.
 | 
					    # Public: Read file contents.
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns a String.
 | 
					    # Returns a String.
 | 
				
			||||||
    def data
 | 
					    def data
 | 
				
			||||||
      File.read(@path)
 | 
					      File.read(@fullpath)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Public: Get byte size
 | 
					    # Public: Get byte size
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns an Integer.
 | 
					    # Returns an Integer.
 | 
				
			||||||
    def size
 | 
					    def size
 | 
				
			||||||
      File.size(@path)
 | 
					      File.size(@fullpath)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Public: Get file extension.
 | 
					    # Public: Get file extension.
 | 
				
			||||||
@@ -73,7 +74,7 @@ module Linguist
 | 
				
			|||||||
    #
 | 
					    #
 | 
				
			||||||
    # Returns an Array
 | 
					    # Returns an Array
 | 
				
			||||||
    def extensions
 | 
					    def extensions
 | 
				
			||||||
      basename, *segments = File.basename(path).split(".")
 | 
					      basename, *segments = name.split(".")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      segments.map.with_index do |segment, index|
 | 
					      segments.map.with_index do |segment, index|
 | 
				
			||||||
        "." + segments[index..-1].join(".")
 | 
					        "." + segments[index..-1].join(".")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user