module Ecoportal module API class V1 # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. class PersonSchemas extend Common::BaseClass include Enumerable class_resolver :person_schema_class, "Ecoportal::API::V1::PersonSchema" attr_reader :client # @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. # @return [Schemas] an instance object ready to make schema api requests. def initialize(client) @client = client end # Gets all the schemas via api request. # @return [Enumerable] an `Enumerable` with all schemas already wrapped as `PersonSchema` objects. def get_all response = client.get("/person_schemas") Common::WrappedResponse.new(response, person_schema_class) end # If a `block` is **not** given it calls [Object#to_enum](https://ruby-doc.org/core-2.6.2/Object.html#method-i-to_enum) # Otherwise it calls `get_all`. # @note # - `:params` doesn't really do anything. # - same as #get_all but with block :) # - `to_a` will call `each` (see this [detailed explanation](https://stackoverflow.com/a/45201663/4352306)) # - however, as far as you have an iterator, such as `each`, `to_a` should be last resource (see [this explanation](https://stackoverflow.com/a/44186921/4352306)) # @yield [schema] does some stuff with the schema. # @yieldparam schema [PersonSchema] # @yieldreturn [PersonSchema] # @return [Enumerable] an `Enumerable` with all the person schema objects. def each(params: {}, &block) return to_enum(:each) unless block get_all.each(&block) end end end end end require 'ecoportal/api/v1/person_schema'