Class: Audiences::Scim::ResourcesQuery

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/audiences/scim/resources_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, resource:, **options) ⇒ ResourcesQuery

Returns a new instance of ResourcesQuery.



14
15
16
17
18
# File 'lib/audiences/scim/resources_query.rb', line 14

def initialize(client, resource:, **options)
  @client = client
  @resource = resource
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/audiences/scim/resources_query.rb', line 12

def options
  @options
end

#resourceObject (readonly)

Returns the value of attribute resource.



12
13
14
# File 'lib/audiences/scim/resources_query.rb', line 12

def resource
  @resource
end

Instance Method Details

#allObject



20
21
22
# File 'lib/audiences/scim/resources_query.rb', line 20

def all
  to_enum(:each, all: true)
end

#each(all: false, &block) ⇒ Object



24
25
26
27
# File 'lib/audiences/scim/resources_query.rb', line 24

def each(all: false, &block)
  resources.each(&block)
  next_page&.each(all: true, &block) if all
end

#next_indexObject



49
50
51
# File 'lib/audiences/scim/resources_query.rb', line 49

def next_index
  start_index + per_page
end

#next_pageObject



53
54
55
56
57
# File 'lib/audiences/scim/resources_query.rb', line 53

def next_page
  return unless next_page?

  ResourcesQuery.new(@client, resource: @resource, **@options, startIndex: next_index)
end

#next_page?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/audiences/scim/resources_query.rb', line 33

def next_page?
  start_index + per_page <= total_results
end

#per_pageObject



41
42
43
# File 'lib/audiences/scim/resources_query.rb', line 41

def per_page
  response["itemsPerPage"].to_i
end

#resourcesObject



29
30
31
# File 'lib/audiences/scim/resources_query.rb', line 29

def resources
  @resources ||= response.fetch("Resources", [])
end

#start_indexObject



37
38
39
# File 'lib/audiences/scim/resources_query.rb', line 37

def start_index
  response.fetch("startIndex", 1)
end

#total_resultsObject



45
46
47
# File 'lib/audiences/scim/resources_query.rb', line 45

def total_results
  response["totalResults"].to_i
end