Module: Serega::InstanceMethods
- Included in:
- Serega
- Defined in:
- lib/serega.rb
Overview
Serializers instance methods
Instance Method Summary collapse
-
#as_json(object, opts = {}) ⇒ Hash
Serializes provided object as JSON.
-
#call(object, opts = {}) ⇒ Hash
Serializes provided object to Hash.
-
#initialize(opts = FROZEN_EMPTY_HASH) ⇒ Object
Instantiates new Serega class.
-
#map ⇒ Array<Serega::SeregaMapPoint>
Array of MapPoints, which are attributes combined with nested attributes.
- #to_h(object, opts = {}) ⇒ Object
-
#to_json(object, opts = {}) ⇒ Hash
Serializes provided object to JSON string.
Instance Method Details
#as_json(object, opts = {}) ⇒ Hash
Serializes provided object as JSON
310 311 312 313 |
# File 'lib/serega.rb', line 310 def as_json(object, opts = {}) json = to_json(object, opts) config.from_json.call(json) end |
#call(object, opts = {}) ⇒ Hash
Serializes provided object to Hash
273 274 275 276 277 278 |
# File 'lib/serega.rb', line 273 def call(object, opts = {}) self.class::CheckSerializeParams.new(opts).validate opts[:context] ||= {} serialize(object, opts) end |
#initialize(opts = FROZEN_EMPTY_HASH) ⇒ Object
Instantiates new Serega class
258 259 260 261 |
# File 'lib/serega.rb', line 258 def initialize(opts = FROZEN_EMPTY_HASH) @opts = (opts == FROZEN_EMPTY_HASH) ? opts : prepare_modifiers(opts) self.class::CheckInitiateParams.new(@opts).validate if opts.fetch(:check_initiate_params) { config.check_initiate_params } end |
#map ⇒ Array<Serega::SeregaMapPoint>
Array of MapPoints, which are attributes combined with nested attributes. This map can be traversed to find currently serializing attributes.
320 321 322 |
# File 'lib/serega.rb', line 320 def map @map ||= self.class::SeregaMap.call(opts) end |
#to_h(object, opts = {}) ⇒ Object
281 282 283 |
# File 'lib/serega.rb', line 281 def to_h(object, opts = {}) call(object, opts) end |
#to_json(object, opts = {}) ⇒ Hash
Serializes provided object to JSON string
295 296 297 298 |
# File 'lib/serega.rb', line 295 def to_json(object, opts = {}) hash = to_h(object, opts) config.to_json.call(hash) end |