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.
413 414 415 |
# File 'lib/serega.rb', line 413 def plan @plan end |
Instance Method Details
#call(object, opts = nil) ⇒ Hash
Serializes provided object to Hash
425 426 427 428 |
# File 'lib/serega.rb', line 425 def call(object, opts = nil) opts = prepare_initial_serialization_opts(object, opts) serialize(object, opts) end |
#initialize(opts = nil) ⇒ Object
Instantiates new Serega class
394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/serega.rb', line 394 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)
447 448 449 450 451 |
# File 'lib/serega.rb', line 447 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
431 432 433 |
# File 'lib/serega.rb', line 431 def to_h(object, opts = nil) call(object, opts) end |