Sha256: f67bf749b7cb95aaf5d97bc97dc84b7078b91097bde0d9f63229e8abaad95563

Contents?: true

Size: 1.27 KB

Versions: 65

Compression:

Stored size: 1.27 KB

Contents

require 'linguist/blob_helper'

module Linguist
  # A FileBlob is a wrapper around a File object to make it quack
  # like a Grit::Blob. It provides the basic interface: `name`,
  # `data`, and `size`.
  class FileBlob
    include BlobHelper

    # Public: Initialize a new FileBlob from a path
    #
    # path      - A path String that exists on the file system.
    # base_path - Optional base to relativize the path
    #
    # Returns a FileBlob.
    def initialize(path, base_path = nil)
      @path = path
      @name = base_path ? path.sub("#{base_path}/", '') : path
    end

    # Public: Filename
    #
    # Examples
    #
    #   FileBlob.new("/path/to/linguist/lib/linguist.rb").name
    #   # =>  "/path/to/linguist/lib/linguist.rb"
    #
    #   FileBlob.new("/path/to/linguist/lib/linguist.rb",
    #                "/path/to/linguist").name
    #   # =>  "lib/linguist.rb"
    #
    # Returns a String
    attr_reader :name

    # Public: Read file permissions
    #
    # Returns a String like '100644'
    def mode
      File.stat(@path).mode.to_s(8)
    end

    # Public: Read file contents.
    #
    # Returns a String.
    def data
      File.read(@path)
    end

    # Public: Get byte size
    #
    # Returns an Integer.
    def size
      File.size(@path)
    end
  end
end

Version data entries

65 entries across 65 versions & 4 rubygems

Version Path
github-linguist-2.10.8 lib/linguist/file_blob.rb
github-linguist-2.10.7 lib/linguist/file_blob.rb
github-linguist-2.10.5 lib/linguist/file_blob.rb
github-linguist-2.10.0 lib/linguist/file_blob.rb
github-linguist-2.9.7 lib/linguist/file_blob.rb
gitlab-linguist-2.9.6 lib/linguist/file_blob.rb
gitlab-linguist-2.9.5 lib/linguist/file_blob.rb
github-linguist-2.9.5 lib/linguist/file_blob.rb
github-linguist-2.9.4 lib/linguist/file_blob.rb
github-linguist-2.9.3 lib/linguist/file_blob.rb
github-linguist-2.8.12 lib/linguist/file_blob.rb
github-linguist-2.8.9 lib/linguist/file_blob.rb
github-linguist-2.8.8 lib/linguist/file_blob.rb
github-linguist-2.8.7 lib/linguist/file_blob.rb
github-linguist-2.8.6 lib/linguist/file_blob.rb
github-linguist-2.8.5 lib/linguist/file_blob.rb
github-linguist-2.8.4 lib/linguist/file_blob.rb
github-linguist-2.8.3 lib/linguist/file_blob.rb
github-linguist-2.8.2 lib/linguist/file_blob.rb
github-linguist-2.8.1 lib/linguist/file_blob.rb