Class: Grit::GitRuby::DirectoryEntry
- Inherits:
-
Object
- Object
- Grit::GitRuby::DirectoryEntry
- Defined in:
- lib/grit/git-ruby/object.rb,
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.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/grit/git-ruby/object.rb', line 105 def initialize(mode, filename, sha1o) @mode = 0 mode.each_byte do |i| @mode = (@mode << 3) | (i-'0'[0]) end @name = filename @sha1 = sha1o if ![S_IFLNK, S_IFDIR, S_IFREG].include?(@mode & S_IFMT) raise RuntimeError, "unknown type for directory entry" end end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
104 105 106 |
# File 'lib/grit/git-ruby/object.rb', line 104 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
104 105 106 |
# File 'lib/grit/git-ruby/object.rb', line 104 def name @name end |
#sha1 ⇒ Object
Returns the value of attribute sha1.
104 105 106 |
# File 'lib/grit/git-ruby/object.rb', line 104 def sha1 @sha1 end |
Instance Method Details
#format_mode ⇒ Object
154 155 156 |
# File 'lib/grit/git-ruby/object.rb', line 154 def format_mode "%06o" % @mode end |
#format_type ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/grit/git-ruby/object.rb', line 143 def format_type case type when :link 'link' when :directory 'tree' when :file 'blob' end end |
#raw ⇒ Object
158 159 160 |
# File 'lib/grit/git-ruby/object.rb', line 158 def raw "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")] end |
#type ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/grit/git-ruby/object.rb', line 117 def type case @mode & S_IFMT 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
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/grit/git-ruby/object.rb', line 130 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 else raise RuntimeError, "invalid type" end end |