Class: Ecoportal::API::V1::PersonSchema
Instance Attribute Summary
#_key, #_parent
Instance Method Summary
collapse
#as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_one, #initial_doc, #initialize, #original_doc, passthrough, #print_pretty, #replace_doc!, #replace_original_doc!, #reset!, #to_json
#class_resolver, #redef_without_warning, #resolve_class
Instance Method Details
#[](id) ⇒ Object
25
26
27
28
|
# File 'lib/ecoportal/api/v1/person_schema.rb', line 25
def [](id)
@fields_by_alt_id or index_fields
@fields_by_id[id] || @fields_by_alt_id[id]
end
|
#fields ⇒ Object
10
11
12
13
|
# File 'lib/ecoportal/api/v1/person_schema.rb', line 10
def fields
@fields_by_id or index_fields
@fields_by_id.values
end
|
#fields_by_alt_id ⇒ Object
20
21
22
23
|
# File 'lib/ecoportal/api/v1/person_schema.rb', line 20
def fields_by_alt_id
@fields_by_alt_id or index_fields
@fields_by_alt_id
end
|
#fields_by_id ⇒ Object
15
16
17
18
|
# File 'lib/ecoportal/api/v1/person_schema.rb', line 15
def fields_by_id
@fields_by_id or index_fields
@fields_by_id
end
|
#index_fields ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ecoportal/api/v1/person_schema.rb', line 30
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
|
#initialize_details(details) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/ecoportal/api/v1/person_schema.rb', line 41
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
|