Class: Algebrick::Serializers2::AbstractConverter
- Inherits:
-
Object
- Object
- Algebrick::Serializers2::AbstractConverter
show all
- Includes:
- TypeCheck
- Defined in:
- lib/algebrick/serializers2/abstract.rb
Constant Summary
- CannotConvert =
Algebrick.atom
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods included from TypeCheck
#Child!, #Child?, #Match!, #Match?, #Type!, #Type?, error
Class Method Details
+ (Object) converts(from, to)
20
21
22
23
|
# File 'lib/algebrick/serializers2/abstract.rb', line 20
def self.converts(from, to)
@from = from
@to = to
end
|
25
26
27
28
|
# File 'lib/algebrick/serializers2/abstract.rb', line 25
def self.from
@from || (superclass.from if superclass < AbstractConverter) or
raise('from not defined')
end
|
30
31
32
33
|
# File 'lib/algebrick/serializers2/abstract.rb', line 30
def self.to
@to || (superclass.to if superclass < AbstractConverter) or
raise('to not defined')
end
|
Instance Method Details
- (Object) call(data, from, options = {})
48
49
50
51
52
53
54
|
# File 'lib/algebrick/serializers2/abstract.rb', line 48
def call(data, from, options = {})
if from == self.from
converted_data = catch(CannotConvert) { convert data, options }
return converted_data, to if CannotConvert != converted_data
end
return data, from
end
|
- (Object) cannot_convert
60
61
62
|
# File 'lib/algebrick/serializers2/abstract.rb', line 60
def cannot_convert
throw CannotConvert, CannotConvert
end
|
- (Object) convert(data, options = {})
43
44
45
|
# File 'lib/algebrick/serializers2/abstract.rb', line 43
def convert(data, options = {})
raise NotImplementedError
end
|
35
36
37
|
# File 'lib/algebrick/serializers2/abstract.rb', line 35
def from
self.class.from
end
|
39
40
41
|
# File 'lib/algebrick/serializers2/abstract.rb', line 39
def to
self.class.to
end
|