lib/ecoportal/api/v1/person.rb in ecoportal-api-0.4.3 vs lib/ecoportal/api/v1/person.rb in ecoportal-api-0.5.0
- old
+ new
@@ -6,16 +6,18 @@
# @attr name [String] the name of the person.
# @attr supervisor_id [String] internal or external id of the supervisor of this person.
# @attr_reader subordinates [Integer] the number of people this person is supervisor of.
# @attr details [PersonDetails, nil] the details of the person or `nil` if missing.
class Person < Common::BaseModel
- passthrough :id, :external_id, :name, :email, :supervisor_id, :subordinates
+ passthrough :id, :external_id, :name, :email, :supervisor_id, :subordinates, :filter_tags
class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema"
class_resolver :person_details_class, "Ecoportal::API::V1::PersonDetails"
embeds_one :details, nullable: true, klass: :person_details_class
+ VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
+
# Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
#
# **Example Usage**:
# ```ruby
# API_KEY = 'some-private-api-key-version'
@@ -35,9 +37,25 @@
# Sets the supervisor of a person.
# @param person [Person, nil] the supervisor of this person.
def supervisor=(person)
self.supervisor_id = person&.id || person&.external_id
+ end
+
+ # Validates the string tags of the array, and sets the `filter_tags` property of the account.
+ # @note all is set in upper case.
+ # @raise [Exception] if there was any invalid string tag.
+ # @param value [Array<String>] array of tags.
+ def filter_tags=(value)
+ unless value.is_a?(Array)
+ raise "filter_tags= needs to be passed an Array, got #{value.class}"
+ end
+ doc["filter_tags"] = value.map do |tag|
+ unless tag.match(VALID_TAG_REGEX)
+ raise "Invalid filter tag #{tag.inspect}"
+ end
+ tag.upcase
+ end
end
def as_json
super.merge "details" => details&.as_json
end