Class: Grit::GitRuby::DirectoryEntry
- Inherits:
-
Object
- Object
- Grit::GitRuby::DirectoryEntry
- Defined in:
- lib/grit/git-ruby/git_object.rb
Constant Summary collapse
- S_IFMT =
00170000
- S_IFLNK =
0120000
- S_IFREG =
0100000
- S_IFDIR =
0040000
- S_IFGITLINK =
0160000
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sha1 ⇒ Object
Returns the value of attribute sha1.
Instance Method Summary collapse
- #format_mode ⇒ Object
- #format_type ⇒ Object
-
#initialize(mode, filename, sha1o) ⇒ DirectoryEntry
constructor
A new instance of DirectoryEntry.
- #raw ⇒ Object
- #type ⇒ Object
- #type=(type) ⇒ Object
Constructor Details
#initialize(mode, filename, sha1o) ⇒ DirectoryEntry
Returns a new instance of DirectoryEntry.
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/grit/git-ruby/git_object.rb', line 116 def initialize(mode, filename, sha1o) @mode = 0 mode.each_byte do |i| @mode = (@mode << 3) | (i-'0'.getord(0)) end @name = filename @sha1 = sha1o if ![S_IFLNK, S_IFDIR, S_IFREG, S_IFGITLINK].include?(@mode & S_IFMT) raise RuntimeError, "unknown type for directory entry" end end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
115 116 117 |
# File 'lib/grit/git-ruby/git_object.rb', line 115 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
115 116 117 |
# File 'lib/grit/git-ruby/git_object.rb', line 115 def name @name end |
#sha1 ⇒ Object
Returns the value of attribute sha1.
115 116 117 |
# File 'lib/grit/git-ruby/git_object.rb', line 115 def sha1 @sha1 end |
Instance Method Details
#format_mode ⇒ Object
171 172 173 |
# File 'lib/grit/git-ruby/git_object.rb', line 171 def format_mode "%06o" % @mode end |
#format_type ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/grit/git-ruby/git_object.rb', line 158 def format_type case type when :link 'link' when :directory 'tree' when :file 'blob' when :submodule 'commit' end end |
#raw ⇒ Object
175 176 177 |
# File 'lib/grit/git-ruby/git_object.rb', line 175 def raw "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")] end |
#type ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/grit/git-ruby/git_object.rb', line 128 def type case @mode & S_IFMT when S_IFGITLINK @type = :submodule when S_IFLNK @type = :link when S_IFDIR @type = :directory when S_IFREG @type = :file else raise RuntimeError, "unknown type for directory entry" end end |
#type=(type) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/grit/git-ruby/git_object.rb', line 143 def type=(type) case @type when :link @mode = (@mode & ~S_IFMT) | S_IFLNK when :directory @mode = (@mode & ~S_IFMT) | S_IFDIR when :file @mode = (@mode & ~S_IFMT) | S_IFREG when :submodule @mode = (@mode & ~S_IFMT) | S_IFGITLINK else raise RuntimeError, "invalid type" end end |