Class: Rosetta::Serializers::Base
- Inherits:
-
Object
- Object
- Rosetta::Serializers::Base
- Defined in:
- lib/rosetta/serializers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object (also: #serialize)
-
#initialize(elements) ⇒ Base
constructor
A new instance of Base.
- #to_proc ⇒ Object
Constructor Details
#initialize(elements) ⇒ Base
Returns a new instance of Base.
31 32 33 34 |
# File 'lib/rosetta/serializers/base.rb', line 31 def initialize(elements) @elements = elements.dup.freeze validate_input! end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
8 9 10 |
# File 'lib/rosetta/serializers/base.rb', line 8 def elements @elements end |
Class Method Details
.call(elements) ⇒ Object
19 20 21 22 23 |
# File 'lib/rosetta/serializers/base.rb', line 19 def call(elements) new(elements).call rescue StandardError raise SerializationError end |
.inherited(new_serializer) ⇒ Object
13 14 15 16 17 |
# File 'lib/rosetta/serializers/base.rb', line 13 def inherited(new_serializer) key = new_serializer.name.match(/^(.*?)(Serializer)?$/)[1] key = key.split("::").last Serializers.register(key.underscore.to_sym, new_serializer) end |
.serialize ⇒ Object
24 25 26 27 28 |
# File 'lib/rosetta/serializers/base.rb', line 24 def call(elements) new(elements).call rescue StandardError raise SerializationError end |
.to_proc ⇒ Object
26 27 28 |
# File 'lib/rosetta/serializers/base.rb', line 26 def to_proc proc { |*args, &block| self.call(*args, &block) } end |
Instance Method Details
#call ⇒ Object Also known as: serialize
36 37 38 |
# File 'lib/rosetta/serializers/base.rb', line 36 def call raise NotImplementedError end |
#to_proc ⇒ Object
41 42 43 |
# File 'lib/rosetta/serializers/base.rb', line 41 def to_proc proc { |*args, &block| self.call(*args, &block) } end |