module Ecoportal module API class V1 class PersonSchema < Common::BaseModel passthrough :id, :name passthrough :enable_tags, :tags class_resolver :schema_field_class, "Ecoportal::API::V1::SchemaField" def fields @fields_by_id or index_fields @fields_by_id.values end def fields_by_id @fields_by_id or index_fields @fields_by_id end def fields_by_alt_id @fields_by_alt_id or index_fields @fields_by_alt_id end def [](id) @fields_by_alt_id or index_fields @fields_by_id[id] || @fields_by_alt_id[id] end def index_fields @fields_by_id = {} @fields_by_alt_id = {} doc["fields"].each do |field| wrapped = schema_field_class.new(field) @fields_by_id[wrapped.id] = wrapped @fields_by_alt_id[wrapped.alt_id] = wrapped end end def initialize_details(details) details.schema_id = id details.doc["fields"] = fields.map do |field| field.doc.slice(*%w[id alt_id name multiple type shared]).merge( "value" => field.multiple ? [] : nil ) end end end end end end require 'ecoportal/api/v1/schema_field'