module DataClass::ClassMethods
Public Instance Methods
json_attributes()
click to toggle source
# File lib/emery/dataclass.rb, line 51 def json_attributes @json_attributes end
jsoner_deserialize(json_value)
click to toggle source
# File lib/emery/dataclass.rb, line 71 def jsoner_deserialize(json_value) T.check(T.hash(String, NilableUntyped), json_value) parameters = @json_attributes.map do |attr, attr_type| attr_value = json_value[attr.to_s] [attr, Jsoner.deserialize(attr_type, attr_value)] end return self.new parameters.to_h end
jsoner_serialize(value)
click to toggle source
# File lib/emery/dataclass.rb, line 80 def jsoner_serialize(value) T.check(self, value) attrs = @json_attributes.map do |attr, attr_type| [attr, Jsoner.serialize(attr_type, value.send(attr))] end return attrs.to_h end
val(name, type)
click to toggle source
# File lib/emery/dataclass.rb, line 55 def val(name, type) if @json_attributes == nil @json_attributes = {} end @json_attributes[name] = type attr_reader name end
var(name, type)
click to toggle source
# File lib/emery/dataclass.rb, line 63 def var(name, type) if @json_attributes == nil @json_attributes = {} end @json_attributes[name] = type attr_accessor name end