Class: Aptible::Auth::User
- Defined in:
- lib/aptible/auth/user.rb
Instance Method Summary collapse
- #operations ⇒ Object
- #organizations ⇒ Object
-
#roles_with_organizations ⇒ Object
Returns roles with their organizations pre-loaded to avoid N+1 API calls when iterating through roles and accessing role.organization.
Methods inherited from Resource
Instance Method Details
#operations ⇒ Object
23 24 25 26 |
# File 'lib/aptible/auth/user.rb', line 23 def operations # TODO: Implement query params for /operations [] end |
#organizations ⇒ Object
17 18 19 20 21 |
# File 'lib/aptible/auth/user.rb', line 17 def organizations # Establish uniqueness of requests before loading all organizations # We can do this by reading the `organization` link for each role roles.map(&:links).map(&:organization).uniq(&:href).map(&:get) end |
#roles_with_organizations ⇒ Object
Returns roles with their organizations pre-loaded to avoid N+1 API calls when iterating through roles and accessing role.organization. Makes 2 backend requests: one for orgs, one for roles.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aptible/auth/user.rb', line 31 def roles_with_organizations orgs_by_href = Organization.all(token: token, headers: headers) .index_by(&:href) roles.tap do |all_roles| all_roles.each do |role| org = orgs_by_href[role.links[:organization].href] role.instance_variable_set(:@organization, org) end end end |