Class: IknowParams::Serializer::Renum

Inherits:
IknowParams::Serializer show all
Defined in:
lib/iknow_params/serializer.rb

Overview

Abstract serializer for renum constants.

Instance Attribute Summary

Attributes inherited from IknowParams::Serializer

#clazz

Instance Method Summary collapse

Methods inherited from IknowParams::Serializer

for, for!, #initialize, json_value?, #matches_type!, #matches_type?, singleton

Constructor Details

This class inherits a constructor from IknowParams::Serializer

Instance Method Details

#dump(val, json: nil) ⇒ Object



337
338
339
340
# File 'lib/iknow_params/serializer.rb', line 337

def dump(val, json: nil)
  matches_type!(val)
  val.name
end

#load(str) ⇒ Object



329
330
331
332
333
334
335
# File 'lib/iknow_params/serializer.rb', line 329

def load(str)
  val = clazz.with_name(str)
  if val.nil?
    raise LoadError.new("Invalid enumeration constant: '#{str}'")
  end
  val
end