Class: Keycloak::Utils::RepresentationIterator
- Inherits:
-
Object
- Object
- Keycloak::Utils::RepresentationIterator
- Includes:
- Enumerable
- Defined in:
- lib/keycloak/utils/representation_iterator.rb
Overview
RepresentationIterator provides ability to enable lazy loading if necessary.
NOTE: It’s worth noting that ‘to_a` may be costly if you have a large dataset of users, which could cause out-of-memory, but using `each` instead of `to_a` could save you if you really want iterate all users.
Constant Summary collapse
- DEFAULT_PER_PAGE =
30
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#first ⇒ Object
Returns the value of attribute first.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#till ⇒ Object
Returns the value of attribute till.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(client, params, per_page: DEFAULT_PER_PAGE, till: nil, &block) ⇒ RepresentationIterator
constructor
A new instance of RepresentationIterator.
Constructor Details
#initialize(client, params, per_page: DEFAULT_PER_PAGE, till: nil, &block) ⇒ RepresentationIterator
Returns a new instance of RepresentationIterator.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/keycloak/utils/representation_iterator.rb', line 16 def initialize(client, params, per_page: DEFAULT_PER_PAGE, till: nil, &block) @client = client @params = params @params[:first] ||= 0 @first = @params[:first] @till = @params[:max] || till @per_page = per_page @block = block @data = [] @cursor = 0 end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
14 15 16 |
# File 'lib/keycloak/utils/representation_iterator.rb', line 14 def cursor @cursor end |
#first ⇒ Object
Returns the value of attribute first.
13 14 15 |
# File 'lib/keycloak/utils/representation_iterator.rb', line 13 def first @first end |
#per_page ⇒ Object
Returns the value of attribute per_page.
13 14 15 |
# File 'lib/keycloak/utils/representation_iterator.rb', line 13 def per_page @per_page end |
#till ⇒ Object
Returns the value of attribute till.
13 14 15 |
# File 'lib/keycloak/utils/representation_iterator.rb', line 13 def till @till end |
Instance Method Details
#each ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/keycloak/utils/representation_iterator.rb', line 35 def each while true return if at_end? _fetch_next if @data.empty? || @cursor >= @data.size return if @data.empty? yield @data[@cursor] @cursor += 1 end end |