Class: Ecoportal::API::V1::PersonDetails
- Inherits:
-
Common::BaseModel
- Object
- Common::BaseModel
- Ecoportal::API::V1::PersonDetails
- Defined in:
- lib/ecoportal/api/v1/person_details.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Common::BaseModel
Instance Method Summary collapse
-
#[](id) ⇒ String, ...
Gets the value of one specific field of the PersonDetails.
-
#[]=(id, value) ⇒ void
Sets the value to one specific field of the PersonDetails.
- #as_json ⇒ Object
-
#fields ⇒ Array<SchemaFieldValue>
Gets all the fields of the PersonDetails.
-
#get_field(id) ⇒ nil, SchemaFieldValue
Gets one specific field of the PersonDetails.
-
#schema_id=(value) ⇒ Object
Sets the
idof the PersonDetails.
Methods inherited from Common::BaseModel
#as_update, #consolidate!, #dirty?, #doc, embeds_one, #initialize, #original_doc, passthrough, #print, #reset!, #to_json
Methods included from Common::BaseClass
#class_resolver, #resolve_class
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::BaseModel
Instance Method Details
#[](id) ⇒ String, ...
Gets the value of one specific field of the PersonDetails.
41 42 43 |
# File 'lib/ecoportal/api/v1/person_details.rb', line 41 def [](id) get_field(id)&.value end |
#[]=(id, value) ⇒ void
This method returns an undefined value.
Sets the value to one specific field of the PersonDetails.
48 49 50 51 52 53 54 |
# File 'lib/ecoportal/api/v1/person_details.rb', line 48 def []=(id, value) if field = get_field(id) field.value = value else raise "details[#{id.inspect}] is missing. Did you forget to load the schema?" end end |
#as_json ⇒ Object
9 10 11 |
# File 'lib/ecoportal/api/v1/person_details.rb', line 9 def as_json super.merge "fields" => fields.map(&:as_json) end |
#fields ⇒ Array<SchemaFieldValue>
Gets all the fields of the PersonDetails.
23 24 25 26 27 28 |
# File 'lib/ecoportal/api/v1/person_details.rb', line 23 def fields return @fields if defined?(@fields) @fields = (doc["fields"] || []).each_with_index.map do |field, i| schema_field_value_class.new(field, parent: self, key: ["fields", i]) end end |
#get_field(id) ⇒ nil, SchemaFieldValue
Gets one specific field of the PersonDetails.
33 34 35 36 |
# File 'lib/ecoportal/api/v1/person_details.rb', line 33 def get_field(id) @fields_by_id or index_fields @fields_by_id[id] || @fields_by_alt_id[id] end |
#schema_id=(value) ⇒ Object
unless the new id is nil, this does not reset the fields.
Sets the id of the PersonDetails.
16 17 18 19 |
# File 'lib/ecoportal/api/v1/person_details.rb', line 16 def schema_id=(value) @fields = [] if value.nil? doc["schema_id"] = value end |