Class: Plurall::Coordinators
- Inherits:
-
Object
- Object
- Plurall::Coordinators
- Includes:
- Enumerable
- Defined in:
- lib/plurall/coordinators.rb
Overview
Public: A list of school coordinators that supports pagination.
Examples
Plurall.coordinators(school_id: 123456).each do |coordinator|
puts coordinator.name
end
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
Instance Method Summary collapse
-
#all(&block) ⇒ Object
Public: Iterates all coordinators.
-
#data ⇒ Object
Public: Returns the list of coordinators as a Hash.
-
#each(&block) ⇒ Object
Public: Iterates the list of coordinators.
-
#initialize(response) ⇒ Coordinators
constructor
Internal: Create a new object from a GraphQL API response.
-
#inspect ⇒ Object
Internal: Returns a string representation of the list.
-
#next ⇒ Object
Public: Retrieve the next page of coordinators.
-
#next? ⇒ Boolean
Public: Whether there are more coordinators available.
-
#next_cursor ⇒ Object
Internal: The next cursor used for pagination.
-
#prev ⇒ Object
Public: Retrieve the previous page of coordinators.
-
#prev? ⇒ Boolean
Public: Whether there are previous coordinators available.
-
#prev_cursor ⇒ Object
Internal: The previous cursor used for pagination.
-
#school_id ⇒ Object
Public: Returns the school id for list of coordinators as a String.
-
#total_count ⇒ Object
Public: Returns the number of coordinators as an Integer.
Constructor Details
#initialize(response) ⇒ Coordinators
Internal: Create a new object from a GraphQL API response.
response - The GraphQL API response as a GraphQL::Client::Response.
22 23 24 |
# File 'lib/plurall/coordinators.rb', line 22 def initialize response @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
15 16 17 |
# File 'lib/plurall/coordinators.rb', line 15 def response @response end |
Instance Method Details
#all(&block) ⇒ Object
Public: Iterates all coordinators.
Several API calls may be made to retrieve all by repeatedly calling #next until #next? returns ‘false`.
Examples
Plurall.coordinators(school_id: 123456).all do |coordinator|
puts coordinator.name
end
Yields a coordinator object to the block.
Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/plurall/coordinators.rb', line 78 def all &block return enum_for :all unless block page = self loop do page.each(&block) page = page.next break if page.nil? end end |
#data ⇒ Object
Public: Returns the list of coordinators as a Hash.
34 35 36 |
# File 'lib/plurall/coordinators.rb', line 34 def data response.data.to_h end |
#each(&block) ⇒ Object
Public: Iterates the list of coordinators.
Examples
Plurall.coordinators(school_id: 123456).each do |coordinator|
puts coordinator.name
end
Yields a coordinator object to the block.
Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
57 58 59 60 61 |
# File 'lib/plurall/coordinators.rb', line 57 def each &block return enum_for :each unless block school_node.coordinators.edges.lazy.map(&:node).each(&block) end |
#inspect ⇒ Object
Internal: Returns a string representation of the list.
171 172 173 |
# File 'lib/plurall/coordinators.rb', line 171 def inspect "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} coordinators:#{total_count}>" end |
#next ⇒ Object
Public: Retrieve the next page of coordinators.
Returns the next page as Plurall::Coordinators, or nil.
119 120 121 122 123 124 |
# File 'lib/plurall/coordinators.rb', line 119 def next return nil unless next? next_response = Plurall::Api.coordinators school_id: school_id, after: next_cursor self.class.new next_response end |
#next? ⇒ Boolean
Public: Whether there are more coordinators available.
Examples
coordinators = Plurall.coordinators school_id: 123456
coordinators.next?
Returns true or false.
99 100 101 |
# File 'lib/plurall/coordinators.rb', line 99 def next? coordinators_page_info.has_next_page end |
#next_cursor ⇒ Object
Internal: The next cursor used for pagination.
Returns the next cursor as a String, or nil.
108 109 110 111 112 |
# File 'lib/plurall/coordinators.rb', line 108 def next_cursor return nil unless next? coordinators_page_info.end_cursor end |
#prev ⇒ Object
Public: Retrieve the previous page of coordinators.
Examples
coordinators = Plurall.coordinators school_id: 123456
prev_coordinators = coordinators.prev
Returns the previous page as Plurall::Coordinators, or nil.
161 162 163 164 165 166 |
# File 'lib/plurall/coordinators.rb', line 161 def prev return nil unless prev? prev_response = Plurall::Api.coordinators school_id: school_id, before: prev_cursor self.class.new prev_response end |
#prev? ⇒ Boolean
Public: Whether there are previous coordinators available.
Examples
coordinators = Plurall.coordinators school_id: 123456
coordinators.prev?
Returns true or false.
136 137 138 |
# File 'lib/plurall/coordinators.rb', line 136 def prev? coordinators_page_info.has_previous_page end |
#prev_cursor ⇒ Object
Internal: The previous cursor used for pagination.
Returns the previous cursor as a String, or nil.
145 146 147 148 149 |
# File 'lib/plurall/coordinators.rb', line 145 def prev_cursor return nil unless prev? coordinators_page_info.start_cursor end |
#school_id ⇒ Object
Public: Returns the school id for list of coordinators as a String.
40 41 42 |
# File 'lib/plurall/coordinators.rb', line 40 def school_id school_node.id end |
#total_count ⇒ Object
Public: Returns the number of coordinators as an Integer.
28 29 30 |
# File 'lib/plurall/coordinators.rb', line 28 def total_count school_node.coordinators.total_count end |