Class: Spandx::Rubygems::DataFile
- Inherits:
-
Object
- Object
- Spandx::Rubygems::DataFile
- Defined in:
- lib/spandx/rubygems/data_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #batch(size:) ⇒ Object
- #data ⇒ Object
-
#initialize(path, default: {}) ⇒ DataFile
constructor
A new instance of DataFile.
- #save! ⇒ Object
- #size ⇒ Object
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
#path ⇒ Object (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 |
#data ⇒ Object
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 |
#size ⇒ Object
17 18 19 |
# File 'lib/spandx/rubygems/data_file.rb', line 17 def size File.size(path) end |