Class: Hash

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

Direct Known Subclasses

FIRM::Serializable::JSON::ObjectHash

Class Method Summary collapse

Instance Method Summary collapse

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

included

Class Method Details

.json_create(object) ⇒ Hash

Create a new Hash instance from deserialized JSON data.

Parameters:

  • object (Hash)

    deserialized JSON object

Returns:

  • (Hash)

    restored Hash instance



368
369
370
# File 'lib/firm/serializer/json.rb', line 368

def json_create(object)
  json_new(object) { |instance| instance.replace(object['data'].to_h) }
end

Instance Method Details

#as_jsonObject



373
374
375
376
377
# File 'lib/firm/serializer/json.rb', line 373

def as_json(*)
  build_json do |json_data|
    json_data['data'] = collect { |k,v| [k.respond_to?(:as_json) ? k.as_json : k, v.respond_to?(:as_json) ? v.as_json : v] }
  end
end