Sha256: 6c3d37ab87df6090853b441410c1891e78c8cc92520f3109ec21d32eb85e0601

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 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_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

        private

        def schema_field_class
          V1::SchemaField
        end
      end
    end
  end
end
require 'ecoportal/api/v1/schema_field'

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ecoportal-api-0.3.8 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.6 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.5 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.4 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.3 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.1 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.0 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.3.0.pre1 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.2.2 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.2.0 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.12 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.11 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.10 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.9 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.8 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.7 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.6 lib/ecoportal/api/v1/person_schema.rb
ecoportal-api-0.1.5 lib/ecoportal/api/v1/person_schema.rb