Class: Spandx::Rubygems::DataFile

Inherits:
Object
  • Object
show all
Defined in:
lib/spandx/rubygems/data_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, default: {}) ⇒ DataFile

Returns a new instance of DataFile.



8
9
10
11
# File 'lib/spandx/rubygems/data_file.rb', line 8

def initialize(path, default: {})
  @path = path
  @default = default
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/spandx/rubygems/data_file.rb', line 6

def path
  @path
end

Instance Method Details

#batch(size:) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/spandx/rubygems/data_file.rb', line 21

def batch(size:)
  Zlib::GzipWriter.open(path) do |io|
    packer = MessagePack::Packer.new(io)
    packer.write_map_header(size)
    yield packer
    packer.flush
  end
end

#dataObject



13
14
15
# File 'lib/spandx/rubygems/data_file.rb', line 13

def data
  @data ||= read(default: @default)
end

#save!Object



30
31
32
# File 'lib/spandx/rubygems/data_file.rb', line 30

def save!
  write(data)
end

#sizeObject



17
18
19
# File 'lib/spandx/rubygems/data_file.rb', line 17

def size
  File.size(path)
end