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.
-
#preloads ⇒ Hash
Merged preloads of all serialized attributes.
- #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.
352 353 354 |
# File 'lib/serega.rb', line 352 def plan @plan end |
Instance Method Details
#call(object, opts = nil) ⇒ Hash
Serializes provided object to Hash
364 365 366 367 368 369 370 |
# File 'lib/serega.rb', line 364 def call(object, opts = nil) opts = opts ? opts.transform_keys!(&:to_sym) : {} self.class::CheckSerializeParams.new(opts).validate unless opts.empty? opts[:context] ||= {} serialize(object, opts) end |
#initialize(opts = nil) ⇒ Object
Instantiates new Serega class
333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/serega.rb', line 333 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 |
#preloads ⇒ Hash
Returns merged preloads of all serialized attributes.
378 379 380 |
# File 'lib/serega.rb', line 378 def preloads @preloads ||= SeregaUtils::PreloadsConstructor.call(plan) end |
#to_h(object, opts = nil) ⇒ Object
373 374 375 |
# File 'lib/serega.rb', line 373 def to_h(object, opts = nil) call(object, opts) end |