Class: Git::FileRef Private
- Inherits:
-
Data
- Object
- Data
- Git::FileRef
- Defined in:
- lib/git/file_ref.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Immutable value object representing a reference to a file at a specific point in time
FileRef encapsulates the mode, SHA, and path of a file as it exists on one side of a diff. This is used to represent either the source (before) or destination (after) state of a file in a diff operation.
When a file doesn't exist on a side of the diff (e.g., src for new files, dst for deleted files), the entire FileRef should be nil rather than having a FileRef with nil attributes.
Work in progress; this class is internal for now and may be made public in a future release.
Instance Attribute Summary collapse
-
#mode ⇒ String
readonly
The file mode (e.g., '100644' for regular file, '100755' for executable, '120000' for symlink).
-
#path ⇒ String
readonly
The file path relative to repository root.
-
#sha ⇒ String
readonly
The blob SHA (object identifier).
Instance Method Summary collapse
-
#executable? ⇒ Boolean
private
Check if this is an executable file.
-
#mode_bits ⇒ Integer
private
Return the mode as an integer (parsed as octal).
-
#regular_file? ⇒ Boolean
private
Check if this is a regular file (not executable, symlink, etc.).
-
#symlink? ⇒ Boolean
private
Check if this is a symbolic link.
Instance Attribute Details
#mode ⇒ String (readonly)
Returns the file mode (e.g., '100644' for regular file, '100755' for executable, '120000' for symlink).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/git/file_ref.rb', line 36 FileRef = Data.define(:mode, :sha, :path) do # Check if this is a regular file (not executable, symlink, etc.) # # @return [Boolean] true if mode is 100644 # def regular_file? mode == '100644' end # Check if this is an executable file # # @return [Boolean] true if mode is 100755 # def executable? mode == '100755' end # Check if this is a symbolic link # # @return [Boolean] true if mode is 120000 # def symlink? mode == '120000' end # Return the mode as an integer (parsed as octal) # # Useful for bit operations on file permissions. # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # # @return [Integer] the mode as an integer # def mode_bits mode.to_i(8) end end |
#path ⇒ String (readonly)
Returns the file path relative to repository root.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/git/file_ref.rb', line 36 FileRef = Data.define(:mode, :sha, :path) do # Check if this is a regular file (not executable, symlink, etc.) # # @return [Boolean] true if mode is 100644 # def regular_file? mode == '100644' end # Check if this is an executable file # # @return [Boolean] true if mode is 100755 # def executable? mode == '100755' end # Check if this is a symbolic link # # @return [Boolean] true if mode is 120000 # def symlink? mode == '120000' end # Return the mode as an integer (parsed as octal) # # Useful for bit operations on file permissions. # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # # @return [Integer] the mode as an integer # def mode_bits mode.to_i(8) end end |
#sha ⇒ String (readonly)
Returns the blob SHA (object identifier).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/git/file_ref.rb', line 36 FileRef = Data.define(:mode, :sha, :path) do # Check if this is a regular file (not executable, symlink, etc.) # # @return [Boolean] true if mode is 100644 # def regular_file? mode == '100644' end # Check if this is an executable file # # @return [Boolean] true if mode is 100755 # def executable? mode == '100755' end # Check if this is a symbolic link # # @return [Boolean] true if mode is 120000 # def symlink? mode == '120000' end # Return the mode as an integer (parsed as octal) # # Useful for bit operations on file permissions. # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # # @return [Integer] the mode as an integer # def mode_bits mode.to_i(8) end end |
Instance Method Details
#executable? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if this is an executable file
49 50 51 |
# File 'lib/git/file_ref.rb', line 49 def executable? mode == '100755' end |
#mode_bits ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the mode as an integer (parsed as octal)
Useful for bit operations on file permissions.
73 74 75 |
# File 'lib/git/file_ref.rb', line 73 def mode_bits mode.to_i(8) end |
#regular_file? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if this is a regular file (not executable, symlink, etc.)
41 42 43 |
# File 'lib/git/file_ref.rb', line 41 def regular_file? mode == '100644' end |
#symlink? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if this is a symbolic link
57 58 59 |
# File 'lib/git/file_ref.rb', line 57 def symlink? mode == '120000' end |