Sha256: d1172cedf21659d4a68382fc2f15bc5166450206110dfc3851c60903f5771643

Contents?: true

Size: 1.15 KB

Versions: 31

Compression:

Stored size: 1.15 KB

Contents

require 'linguist/blob_helper'
require 'linguist/blob'

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`, `path` and `size`.
  class FileBlob < Blob
    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)
      @fullpath = path
      @path = base_path ? path.sub("#{base_path}/", '') : path
    end

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

    def symlink?
      return @symlink if defined? @symlink
      @symlink = (File.symlink?(@fullpath) rescue false)
    end

    # Public: Read file contents.
    #
    # Returns a String.
    def data
      @data ||= File.read(@fullpath, :encoding => "ASCII-8BIT")
    end

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
github-linguist-9.0.0 lib/linguist/file_blob.rb
github-linguist-8.0.1 lib/linguist/file_blob.rb
github-linguist-8.0.0 lib/linguist/file_blob.rb
github-linguist-7.30.0 lib/linguist/file_blob.rb
github-linguist-7.29.0 lib/linguist/file_blob.rb
github-linguist-7.28.0 lib/linguist/file_blob.rb
github-linguist-7.27.0 lib/linguist/file_blob.rb
github-linguist-7.26.0 lib/linguist/file_blob.rb
github-linguist-7.25.0 lib/linguist/file_blob.rb
github-linguist-7.24.1 lib/linguist/file_blob.rb
github-linguist-7.24.0 lib/linguist/file_blob.rb
github-linguist-7.23.0 lib/linguist/file_blob.rb
github-linguist-7.22.1 lib/linguist/file_blob.rb
github-linguist-7.22.0 lib/linguist/file_blob.rb
github-linguist-7.21.0 lib/linguist/file_blob.rb
github-linguist-7.20.0 lib/linguist/file_blob.rb
github-linguist-7.19.0 lib/linguist/file_blob.rb
github-linguist-7.18.0 lib/linguist/file_blob.rb
github-linguist-7.17.0 lib/linguist/file_blob.rb
github-linguist-7.16.1 lib/linguist/file_blob.rb