Class: Rosetta::Deserializers::Base
- Inherits:
-
Object
- Object
- Rosetta::Deserializers::Base
- Defined in:
- lib/rosetta/deserializers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object (also: #deserialize)
-
#initialize(input) ⇒ Base
constructor
A new instance of Base.
- #to_proc ⇒ Object
Constructor Details
#initialize(input) ⇒ Base
Returns a new instance of Base.
30 31 32 |
# File 'lib/rosetta/deserializers/base.rb', line 30 def initialize(input) @input = input.dup.freeze end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
9 10 11 |
# File 'lib/rosetta/deserializers/base.rb', line 9 def input @input end |
Class Method Details
.call(input) ⇒ Object
18 19 20 21 22 |
# File 'lib/rosetta/deserializers/base.rb', line 18 def call(input) new(input).call rescue StandardError raise DeserializationError end |
.deserialize ⇒ Object
23 24 25 26 27 |
# File 'lib/rosetta/deserializers/base.rb', line 23 def call(input) new(input).call rescue StandardError raise DeserializationError end |
.inherited(new_serializer) ⇒ Object
12 13 14 15 16 |
# File 'lib/rosetta/deserializers/base.rb', line 12 def inherited(new_serializer) key = new_serializer.name.match(/^(.*?)(Deserializer)?$/)[1] key = key.split("::").last Deserializers.register(key.underscore.to_sym, new_serializer) end |
.to_proc ⇒ Object
25 26 27 |
# File 'lib/rosetta/deserializers/base.rb', line 25 def to_proc proc { |*args, &block| self.call(*args, &block) } end |
Instance Method Details
#call ⇒ Object Also known as: deserialize
34 35 36 |
# File 'lib/rosetta/deserializers/base.rb', line 34 def call raise NotImplementedError end |
#to_proc ⇒ Object
39 40 41 |
# File 'lib/rosetta/deserializers/base.rb', line 39 def to_proc proc { |*args, &block| self.call(*args, &block) } end |