Class: Git::FileRef
- Inherits:
-
Data
- Object
- Data
- Git::FileRef
- Defined in:
- lib/git/file_ref.rb
Overview
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.
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
Check if this is an executable file.
-
#mode_bits ⇒ Integer
Return the mode as an integer (parsed as octal).
-
#regular_file? ⇒ Boolean
Check if this is a regular file (not executable, symlink, etc.).
-
#symlink? ⇒ Boolean
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).
33 34 35 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 |
# File 'lib/git/file_ref.rb', line 33 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. # # @return [Integer] the mode as an integer # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # def mode_bits mode.to_i(8) end end |
#path ⇒ String (readonly)
Returns the file path relative to repository root.
33 34 35 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 |
# File 'lib/git/file_ref.rb', line 33 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. # # @return [Integer] the mode as an integer # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # def mode_bits mode.to_i(8) end end |
#sha ⇒ String (readonly)
Returns the blob SHA (object identifier).
33 34 35 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 |
# File 'lib/git/file_ref.rb', line 33 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. # # @return [Integer] the mode as an integer # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # def mode_bits mode.to_i(8) end end |
Instance Method Details
#executable? ⇒ Boolean
Check if this is an executable file
46 47 48 |
# File 'lib/git/file_ref.rb', line 46 def executable? mode == '100755' end |
#mode_bits ⇒ Integer
Return the mode as an integer (parsed as octal)
Useful for bit operations on file permissions.
70 71 72 |
# File 'lib/git/file_ref.rb', line 70 def mode_bits mode.to_i(8) end |
#regular_file? ⇒ Boolean
Check if this is a regular file (not executable, symlink, etc.)
38 39 40 |
# File 'lib/git/file_ref.rb', line 38 def regular_file? mode == '100644' end |
#symlink? ⇒ Boolean
Check if this is a symbolic link
54 55 56 |
# File 'lib/git/file_ref.rb', line 54 def symlink? mode == '120000' end |