Class: Labimotion::OwnerResolver
- Inherits:
-
Object
- Object
- Labimotion::OwnerResolver
- Defined in:
- lib/labimotion/libs/owner_resolver.rb
Overview
OwnerResolver
Builds the owners: option the klass entities read, so rendering a grid of N templates
costs one user query instead of N. Deleted users are included on purpose: a template whose
author has left still has to name somebody, otherwise the grid can only say "unknown" and
an administrator has nothing to act on.
Class Method Summary collapse
-
.find(user_id) ⇒ Object
Single-user fallback for the call sites that ask for ownership without preloading a map.
- .map_for(klasses) ⇒ Object
-
.map_for_ids(ids) ⇒ Object
Same map, from bare user ids — what ShareResolver feeds it, where the ids come from owner share rows rather than a created_by column.
Class Method Details
.find(user_id) ⇒ Object
Single-user fallback for the call sites that ask for ownership without preloading a map.
Same soft-delete scope and same "never break the caller" contract as map_for.
35 36 37 38 39 40 41 42 |
# File 'lib/labimotion/libs/owner_resolver.rb', line 35 def self.find(user_id) return nil if user_id.blank? user_scope.find_by(id: user_id) rescue StandardError => e Labimotion.log_exception(e) nil end |
.map_for(klasses) ⇒ Object
16 17 18 |
# File 'lib/labimotion/libs/owner_resolver.rb', line 16 def self.map_for(klasses) map_for_ids(Array(klasses).filter_map { |klass| klass.try(:created_by) }) end |
.map_for_ids(ids) ⇒ Object
Same map, from bare user ids — what ShareResolver feeds it, where the ids come from owner share rows rather than a created_by column.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/labimotion/libs/owner_resolver.rb', line 22 def self.map_for_ids(ids) ids = Array(ids).compact.uniq return {} if ids.empty? user_scope.where(id: ids).index_by(&:id) rescue StandardError => e # Ownership is decoration on a list that must still render. Labimotion.log_exception(e) {} end |