module Ecoportal module API class V1 class PersonSchema < Common::BaseModel passthrough :id, :name, to: :doc 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 private def schema_field_class V1::SchemaField end end end end end require 'ecoportal/api/v1/schema_field'