Sha256: 92be704e38aaedb51ed93db3b2b5f4829a482c19e0ee3214d5c44a87031e41ce
Contents?: true
Size: 1.21 KB
Versions: 9
Compression:
Stored size: 1.21 KB
Contents
module Ecoportal module API class V1 class PersonDetails < Common::BaseModel passthrough :schema_id, to: :doc def as_json super.merge "fields" => fields.map(&:as_json) end def schema_id=(value) @fields = [] if value.nil? doc["schema_id"] = value end def fields return @fields if defined?(@fields) @fields = (doc["fields"] || []).map do |field| schema_field_value_class.new(field) end end def index_fields @fields_by_id = {} @fields_by_alt_id = {} fields.each do |wrapped| @fields_by_id[wrapped.id] = wrapped @fields_by_alt_id[wrapped.alt_id] = wrapped end end def get_field(id) @fields_by_id or index_fields @fields_by_id[id] || @fields_by_alt_id[id] end def [](id) get_field(id)&.value end def []=(id, value) if field = get_field(id) field.value = value end end private def schema_field_value_class V1::SchemaFieldValue end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems