Class: OfflineSort::Chunk::InputOutput::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/offline_sort/chunk/input_output/base.rb

Direct Known Subclasses

Marshal, MessagePack, Yaml

Constant Summary collapse

MethodNotImplementedError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/offline_sort/chunk/input_output/base.rb', line 10

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



8
9
10
# File 'lib/offline_sort/chunk/input_output/base.rb', line 8

def io
  @io
end

Instance Method Details

#closeObject



35
36
37
# File 'lib/offline_sort/chunk/input_output/base.rb', line 35

def close
  io.close
end

#eachObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/offline_sort/chunk/input_output/base.rb', line 39

def each
  Enumerator.new do |yielder|
    while true
      begin
        yielder.yield(read_entry)
      rescue EOFError
        break
      end
    end
  end
end

#flushObject



26
27
28
# File 'lib/offline_sort/chunk/input_output/base.rb', line 26

def flush
  io.flush
end

#read_entryObject



14
15
16
# File 'lib/offline_sort/chunk/input_output/base.rb', line 14

def read_entry
  raise(MethodNotImplementedError, "#{__method__} must be overridden by #{self.class}")
end

#rewindObject



30
31
32
33
# File 'lib/offline_sort/chunk/input_output/base.rb', line 30

def rewind
  flush
  io.rewind
end

#write_entries(entries) ⇒ Object



22
23
24
# File 'lib/offline_sort/chunk/input_output/base.rb', line 22

def write_entries(entries)
  entries.each { |entry| write_entry(entry) }
end

#write_entry(entry) ⇒ Object



18
19
20
# File 'lib/offline_sort/chunk/input_output/base.rb', line 18

def write_entry(entry)
  raise(MethodNotImplementedError, "#{__method__} must be overridden by #{self.class}")
end