Class: Struct

Inherits:
Object
  • Object
show all
Includes:
FIRM::Serializable::JSON::ContainerPatch
Defined in:
lib/firm/serializer/json.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FIRM::Serializable::JSON::ContainerPatch

included

Class Method Details

.json_create(object) ⇒ Struct

Create a new Struct instance from deserialized JSON data.

Parameters:

  • object (Hash)

    deserialized JSON object

Returns:

  • (Struct)

    restored Set instance



409
410
411
412
413
414
# File 'lib/firm/serializer/json.rb', line 409

def json_create(object)
    json_new(object) do |instance|
      values = object['v']
      instance.members.each_with_index { |n, i| instance[n] = values[i] }
    end
end

Instance Method Details

#as_jsonObject



417
418
419
420
421
422
# File 'lib/firm/serializer/json.rb', line 417

def as_json(*)
  self.class.name.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
  build_json do |json_data|
    json_data['v'] = values.collect { |e| e.respond_to?(:as_json) ? e.as_json : e }
  end
end