Class: EsDumpRestore::Dumpfile
- Inherits:
-
Zip::ZipFile
- Object
- Zip::ZipFile
- EsDumpRestore::Dumpfile
- Defined in:
- lib/es_dump_restore/dumpfile.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_objects_input_stream(&block) ⇒ Object
- #get_objects_output_stream(&block) ⇒ Object
- #index ⇒ Object
- #index=(index) ⇒ Object
- #num_objects ⇒ Object
- #num_objects=(n) ⇒ Object
- #scan_objects(batch_size, &block) ⇒ Object
Class Method Details
.read(filename, &block) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/es_dump_restore/dumpfile.rb', line 15 def self.read(filename, &block) df = Dumpfile.new(filename) begin yield df ensure df.close end end |
.write(filename, &block) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/es_dump_restore/dumpfile.rb', line 6 def self.write(filename, &block) df = Dumpfile.new(filename, Zip::ZipFile::CREATE) begin yield df ensure df.close end end |
Instance Method Details
#get_objects_input_stream(&block) ⇒ Object
24 25 26 |
# File 'lib/es_dump_restore/dumpfile.rb', line 24 def get_objects_input_stream(&block) get_input_stream("objects", &block) end |
#get_objects_output_stream(&block) ⇒ Object
28 29 30 |
# File 'lib/es_dump_restore/dumpfile.rb', line 28 def get_objects_output_stream(&block) get_output_stream("objects", nil, &block) end |
#index ⇒ Object
67 68 69 |
# File 'lib/es_dump_restore/dumpfile.rb', line 67 def index read_json_file("index.json") end |
#index=(index) ⇒ Object
63 64 65 |
# File 'lib/es_dump_restore/dumpfile.rb', line 63 def index=(index) write_json_file("index.json", index) end |
#num_objects ⇒ Object
32 33 34 |
# File 'lib/es_dump_restore/dumpfile.rb', line 32 def num_objects read_json_file("num_objects.json")["num_objects"] end |
#num_objects=(n) ⇒ Object
36 37 38 |
# File 'lib/es_dump_restore/dumpfile.rb', line 36 def num_objects=(n) write_json_file("num_objects.json", {num_objects: n}) end |
#scan_objects(batch_size, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/es_dump_restore/dumpfile.rb', line 40 def scan_objects(batch_size, &block) get_objects_input_stream do |input| loop do commands = "" items = 0 batch_size.times do = input.gets("\n") break if .nil? commands << source = input.gets("\n") commands << source items += 1 end break if commands.empty? yield commands, items end end end |