Class: Pack::Entry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pack/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oid, info, path, ofs = false) ⇒ Entry

Returns a new instance of Entry.



13
14
15
16
17
18
19
20
# File 'lib/pack/entry.rb', line 13

def initialize(oid, info, path, ofs = false)
  @oid   = oid
  @info  = info
  @path  = path
  @ofs   = ofs
  @delta = nil
  @depth = 0
end

Instance Attribute Details

#deltaObject (readonly)

Returns the value of attribute delta.



11
12
13
# File 'lib/pack/entry.rb', line 11

def delta
  @delta
end

#depthObject (readonly)

Returns the value of attribute depth.



11
12
13
# File 'lib/pack/entry.rb', line 11

def depth
  @depth
end

#offsetObject

Returns the value of attribute offset.



10
11
12
# File 'lib/pack/entry.rb', line 10

def offset
  @offset
end

#oidObject (readonly)

Returns the value of attribute oid.



11
12
13
# File 'lib/pack/entry.rb', line 11

def oid
  @oid
end

Instance Method Details

#assign_delta(delta) ⇒ Object



26
27
28
29
# File 'lib/pack/entry.rb', line 26

def assign_delta(delta)
  @delta = delta
  @depth = delta.base.depth + 1
end

#delta_prefixObject



43
44
45
46
47
48
49
50
51
# File 'lib/pack/entry.rb', line 43

def delta_prefix
  return "" unless @delta

  if @ofs
    Numbers::VarIntBE.write(offset - @delta.base.offset)
  else
    [@delta.base.oid].pack("H40")
  end
end

#packed_sizeObject



39
40
41
# File 'lib/pack/entry.rb', line 39

def packed_size
  @delta ? @delta.size : @info.size
end

#packed_typeObject



31
32
33
34
35
36
37
# File 'lib/pack/entry.rb', line 31

def packed_type
  if @delta
    @ofs ? OFS_DELTA : REF_DELTA
  else
    TYPE_CODES.fetch(@info.type)
  end
end

#sort_keyObject



22
23
24
# File 'lib/pack/entry.rb', line 22

def sort_key
  [packed_type, @path&.basename, @path&.dirname, @info.size]
end