Class: Bibliothecary::FileInfo
- Inherits:
-
Object
- Object
- Bibliothecary::FileInfo
- Defined in:
- lib/bibliothecary/file_info.rb
Overview
A representation of a file on the filesystem, with location information and package manager information if needed.
Instance Attribute Summary collapse
-
#folder_path ⇒ Object
readonly
Returns the value of attribute folder_path.
-
#full_path ⇒ Object
readonly
Returns the value of attribute full_path.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
Instance Method Summary collapse
- #contents ⇒ Object
- #groupable? ⇒ Boolean
-
#initialize(folder_path, full_path, contents = nil) ⇒ FileInfo
constructor
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.
- #package_manager ⇒ Object
Constructor Details
#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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bibliothecary/file_info.rb', line 31 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 @parser = nil end |
Instance Attribute Details
#folder_path ⇒ Object (readonly)
Returns the value of attribute folder_path.
9 10 11 |
# File 'lib/bibliothecary/file_info.rb', line 9 def folder_path @folder_path end |
#full_path ⇒ Object (readonly)
Returns the value of attribute full_path.
9 10 11 |
# File 'lib/bibliothecary/file_info.rb', line 9 def full_path @full_path end |
#parser ⇒ Object
Returns the value of attribute parser.
10 11 12 |
# File 'lib/bibliothecary/file_info.rb', line 10 def parser @parser end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
9 10 11 |
# File 'lib/bibliothecary/file_info.rb', line 9 def relative_path @relative_path end |
Instance Method Details
#contents ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bibliothecary/file_info.rb', line 16 def contents @contents ||= if @folder_path.nil? # if we have no folder_path then we aren't dealing with a # file that's actually on the filesystem nil else Bibliothecary.utf8_string(File.read(@full_path)) end end |
#groupable? ⇒ Boolean
55 56 57 |
# File 'lib/bibliothecary/file_info.rb', line 55 def groupable? @parser&.groupable?(self) end |
#package_manager ⇒ Object
12 13 14 |
# File 'lib/bibliothecary/file_info.rb', line 12 def package_manager raise "FileInfo#package_manager() has been removed in bibliothecary 15.0.0. Use parser() instead, which now includes MultiParsers." end |