Roles

Envless.roles.iterate

Stream roles one row at a time

def iterate(
  limit: nil,
  offset: nil,
  search: nil,
  sort_by: nil,
  timeout: nil,
  &block
)

Yields roles individually, fetching the next page only once the current one is drained. Role sets are small, so this exists mainly for symmetry with the other collections and for the ability to stop as soon as you find the row you wanted.

Give it a block to walk every item, or leave the block off for an Enumerator you can stop early, such as with first(10). No request is issued until the first iteration, and breaking out of the loop leaves any remaining pages unfetched.

Example

ruby
require "envless/sdk"

Envless.roles.iterate do |role|
  next if role[:isSystem]

  puts "#{role[:name]} #{role[:permissions].size}"
end

Parameters

ParameterTypeRequiredDescription
limit:IntegerNoPage size fetched behind the scenes, clamped to 100.
offset:IntegerNoRow to start streaming from.
search:String | SymbolNoCase insensitive substring match against role name and description.
sort_by:"updated" | "created" | "name"NoOrder within each group: name (the default) is A to Z, updated and created are newest first. System roles always come first.
timeout:Integer | Float | RationalNoSeconds each attempt of this call may take, redirects and the response body included, before it raises Envless::NetworkError with timeout? set. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

An Enumerator that yields role_resource values until the pages run out.

Reads the roles collection. list returns one page as an Envless::Page with items and pagination, list_all collects every page into an array, and iterate yields one item at a time to a block, fetching the next page only when it gets there. Without a block, iterate returns an Enumerator.

Worth knowing

  • The offset advances by the number of rows actually received, so a role created mid walk can shift the window.
  • System roles are yielded before custom roles, so a loop that breaks on the first row always sees a system role.

Required scopes

roles:read

Underlying endpoint

GET /roles

Request and response schema, every error code, and a live playground.

In TypeScript

envless.roles.iterate()

The same method in @goenvless/sdk, with the same request, retries and errors.