Sha256: db206c6562e2947796c8fecb9e7ed2810e01c46a6c1b2b7ed7ea18ef236e6d0f

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

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_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'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ecoportal-api-0.1.2 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.1 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.0 lib/ecoportal/api/v1/person_schema.rb