lib/ecoportal/api/v1/person_details.rb in ecoportal-api-0.9.7 vs lib/ecoportal/api/v1/person_details.rb in ecoportal-api-0.10.0

- old
+ new

@@ -38,25 +38,25 @@ @fields_by_id[id] || @fields_by_alt_id[id] end # Gets the value of one specific field of the PersonDetails. # @param id [String] the `id` or the `alt_id` of the target field. - # @return [String, Array<String>, Boolean, Array<Boolean>, Date, Array<Date>, Numberic, Array<Numeric>] the value of field or `nil` if missing. + # @return [String, Array<String>, Boolean, Array<Boolean>, Date, Array<Date>, Numberic, Array<Numeric>] + # the value of field or `nil` if missing. def [](id) get_field(id)&.value end # Sets the value to one specific field of the PersonDetails. # @raise MisssingId if the `id` or `alt_id` is missing. # @param id [String] the `id` or the `alt_id` of the target field. # @return [void] def []=(id, value) - if field = get_field(id) - field.value = value - else - raise MissingId.new("details[#{id.inspect}] is missing. Did you forget to load the schema?") - end + msg = "details[#{id.inspect}] is missing. Did you forget to load the schema?" + raise MissingId, msg unless (field = get_field(id)) + + field.value = value end # Checks if an `id` or `alt_id` exists # @param id [String] the `id` or the `alt_id` of the target field. # @return [Boolean] `true` if it exists, `false` otherwise @@ -65,16 +65,18 @@ @fields_by_id.key?(id) || @fields_by_alt_id.key?(id) end # @return [Boolean] `true` if `id` exists and `value` has changed, `false` otherwise def changed?(id, doc = :original) - return false unless field = get_field(id) + return false unless (field = get_field(id)) + field.as_update.key?("value") end def original_value(id) - return nil unless field = get_field(id) + return nil unless (field = get_field(id)) + field.original_doc["value"] end protected @@ -85,10 +87,9 @@ fields.each do |wrapped| @fields_by_id[wrapped.id] = wrapped @fields_by_alt_id[wrapped.alt_id] = wrapped end end - end end end end