Sha256: 46c64b14f410ed306c012093bb7448de1a2f06d8e94b20140009d0f3d9f21874
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 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? super 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_id[wrapped.alt_id] = wrapped end end def [](id) @fields_by_id or index_fields (@fields_by_id[id] || @fields_by_alt_id[id])&.value end def []=(id, value) @fields_by_id or index_fields if field = (@fields_by_id[id] || @fields_by_alt_id[id]) field.value = value end end private def schema_field_value_class V1::SchemaFieldValue end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ecoportal-api-0.1.1 | lib/ecoportal/api/v1/person_details.rb |
ecoportal-api-0.1.0 | lib/ecoportal/api/v1/person_details.rb |