Class: Spark::Serializer::Base
Abstract
- Inherits:
-
Object
- Object
- Spark::Serializer::Base
show all
- Defined in:
- lib/spark/serializer/base.rb
Overview
This class is abstract.
Parent for all serializers
Instance Method Summary
collapse
Instance Method Details
#==(other) ⇒ Object
28
29
30
|
# File 'lib/spark/serializer/base.rb', line 28
def ==(other)
self.to_s == other.to_s
end
|
#batched? ⇒ Boolean
32
33
34
|
# File 'lib/spark/serializer/base.rb', line 32
def batched?
false
end
|
#check_each(data) ⇒ Object
39
40
41
42
43
|
# File 'lib/spark/serializer/base.rb', line 39
def check_each(data)
unless data.respond_to?(:each)
error('Data must be iterable.')
end
end
|
#error(message) ⇒ Object
45
46
47
|
# File 'lib/spark/serializer/base.rb', line 45
def error(message)
raise Spark::SerializeError, message
end
|
#inspect ⇒ Object
57
58
59
|
# File 'lib/spark/serializer/base.rb', line 57
def inspect
%{#<Spark::Serializer:0x#{object_id} "#{self}">}
end
|
#load_from_file(file, *args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/spark/serializer/base.rb', line 17
def load_from_file(file, *args)
return to_enum(__callee__, file, *args) unless block_given?
load_from_io(file, *args).each do |item|
yield item
end
file.close
file.unlink
end
|
#load_from_io(io) ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/spark/serializer/base.rb', line 6
def load_from_io(io)
return to_enum(__callee__, io) unless block_given?
loop do
size = io.read_int_or_eof
break if size == Spark::Constant::DATA_EOF
yield load(io.read(size))
end
end
|
#name ⇒ Object
49
50
51
|
# File 'lib/spark/serializer/base.rb', line 49
def name
self.class.name.split('::').last
end
|
#to_s ⇒ Object
53
54
55
|
# File 'lib/spark/serializer/base.rb', line 53
def to_s
name
end
|
#unbatch! ⇒ Object
36
37
|
# File 'lib/spark/serializer/base.rb', line 36
def unbatch!
end
|