Class: Struct
- Inherits:
-
Object
- Object
- Struct
- Includes:
- FIRM::Serializable::JSON::ContainerPatch
- Defined in:
- lib/firm/serializer/json.rb
Class Method Summary collapse
-
.json_create(object) ⇒ Struct
Create a new Struct instance from deserialized JSON data.
Instance Method Summary collapse
Methods included from FIRM::Serializable::JSON::ContainerPatch
Class Method Details
.json_create(object) ⇒ Struct
Create a new Struct instance from deserialized JSON data.
406 407 408 409 410 411 |
# File 'lib/firm/serializer/json.rb', line 406 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_json ⇒ Object
414 415 416 417 418 419 |
# File 'lib/firm/serializer/json.rb', line 414 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 |