Module: Serega::InstanceMethods
- Included in:
- Serega
- Defined in:
- lib/serega.rb
Overview
Serializers instance methods
Instance Attribute Summary collapse
-
#plan ⇒ Serega::SeregaPlan
readonly
Plan for serialization.
Instance Method Summary collapse
-
#call(object, opts = nil) ⇒ Hash
Serializes provided object to Hash.
-
#initialize(opts = nil) ⇒ Object
Instantiates new Serega class.
-
#to_data(object, opts = nil) ⇒ Data
Serializes provided object to Data objects Patched in: - plugin :root (adds a data-object for a root level keys).
- #to_h(object, opts = nil) ⇒ Object
Instance Attribute Details
#plan ⇒ Serega::SeregaPlan (readonly)
Plan for serialization. This plan can be traversed to find serialized attributes and nested attributes.
414 415 416 |
# File 'lib/serega.rb', line 414 def plan @plan end |
Instance Method Details
#call(object, opts = nil) ⇒ Hash
Serializes provided object to Hash
426 427 428 429 |
# File 'lib/serega.rb', line 426 def call(object, opts = nil) opts = prepare_initial_serialization_opts(object, opts) serialize(object, opts) end |
#initialize(opts = nil) ⇒ Object
Instantiates new Serega class
395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/serega.rb', line 395 def initialize(opts = nil) @opts = if opts.nil? || opts.empty? FROZEN_EMPTY_HASH else opts.transform_keys!(&:to_sym) parse_modifiers(opts) end self.class::CheckInitiateParams.new(@opts).validate if opts&.fetch(:check_initiate_params) { config.check_initiate_params } @plan = self.class::SeregaPlan.call(@opts) end |
#to_data(object, opts = nil) ⇒ Data
Serializes provided object to Data objects Patched in:
- plugin :root (adds a data-object for a root level keys)
448 449 450 451 452 |
# File 'lib/serega.rb', line 448 def to_data(object, opts = nil) opts = prepare_initial_serialization_opts(object, opts) serialized_data = serialize(object, opts) self.class::SeregaDataBuilder.call(self, serialized_data) end |
#to_h(object, opts = nil) ⇒ Object
432 433 434 |
# File 'lib/serega.rb', line 432 def to_h(object, opts = nil) call(object, opts) end |