Sha256: da72dd5518305043a6bc7382aebcaed251fda077132bbba88dde5461f91ba1ce

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

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<PersonSchema>] 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<PersonSchema>] 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'

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ecoportal-api-0.9.7 lib/ecoportal/api/v1/person_schemas.rb
ecoportal-api-0.9.6 lib/ecoportal/api/v1/person_schemas.rb
ecoportal-api-0.9.5 lib/ecoportal/api/v1/person_schemas.rb
ecoportal-api-0.9.4 lib/ecoportal/api/v1/person_schemas.rb
ecoportal-api-0.9.3 lib/ecoportal/api/v1/person_schemas.rb
ecoportal-api-0.9.2 lib/ecoportal/api/v1/person_schemas.rb