Class: Chronicle::Serialization::Serializer
- Inherits:
-
Object
- Object
- Chronicle::Serialization::Serializer
- Defined in:
- lib/chronicle/serialization/serializer.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(record, options = {}) ⇒ Serializer
constructor
Construct a new instance of this serializer.
-
#serializable_hash ⇒ Object
Serialize a record as a hash.
Constructor Details
#initialize(record, options = {}) ⇒ Serializer
Construct a new instance of this serializer.
Parameters:
- options
-
Options for configuring this Serializers
8 9 10 11 12 13 14 15 16 |
# File 'lib/chronicle/serialization/serializer.rb', line 8 def initialize(record, = {}) unless record.is_a?(Chronicle::Serialization::Record) raise(ArgumentError, "Must be a Record. It is a: #{record.class}") end @record = record @options = end |
Class Method Details
.serialize(data) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chronicle/serialization/serializer.rb', line 23 def self.serialize(data) record = if data.is_a?(Chronicle::Models::Base) Chronicle::Serialization::Record.build_from_model(data) elsif data.is_a?(Chronicle::Serialization::Record) data else raise ArgumentError, 'data must be a Chronicle::Models::Base or Chronicle::Serialization::Record' end serializer = new(record) serializer.serializable_hash end |
Instance Method Details
#serializable_hash ⇒ Object
Serialize a record as a hash
19 20 21 |
# File 'lib/chronicle/serialization/serializer.rb', line 19 def serializable_hash raise NotImplementedError end |