Method: Bibliothecary::FileInfo#initialize

Defined in:
lib/bibliothecary/file_info.rb

#initialize(folder_path, full_path, contents = nil) ⇒ FileInfo

If the FileInfo represents an actual file on disk, the contents can be nil and lazy-loaded; we allow contents to be passed in here to allow pulling them from somewhere other than the disk.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bibliothecary/file_info.rb', line 29

def initialize(folder_path, full_path, contents = nil)
  # Note that cleanpath does NOT touch the filesystem,
  # leaving the lazy-load of file contents as the only
  # time we touch the filesystem.

  full_pathname = Pathname.new(full_path)
  @full_path = full_pathname.cleanpath.to_path

  if folder_path.nil?
    # this is the case where we e.g. have filenames from the GitHub API
    # and don't have a local folder
    @folder_path = nil
    @relative_path = @full_path
  else
    folder_pathname = Pathname.new(folder_path)
    @folder_path = folder_pathname.cleanpath.to_path
    @relative_path = full_pathname.relative_path_from(folder_pathname).cleanpath.to_path
  end

  @contents = contents

  @package_manager = nil
end