Class: Servus::Extensions::Lazily::Resolver Private
- Inherits:
-
Object
- Object
- Servus::Extensions::Lazily::Resolver
- Defined in:
- lib/servus/extensions/lazily/resolver.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Performs the actual record resolution for a lazily-declared input.
Handles the decision logic: is the raw value already an instance, nil, an array, or a lookup value? Delegates to the appropriate finder method on the target class.
Class Method Summary collapse
-
.call(raw, klass:, by:, name:) ⇒ Object
private
Resolves a raw value to a record (or collection of records).
Class Method Details
.call(raw, klass:, by:, name:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolves a raw value to a record (or collection of records).
22 23 24 25 26 27 28 |
# File 'lib/servus/extensions/lazily/resolver.rb', line 22 def self.call(raw, klass:, by:, name:) return raw if raw.is_a?(klass) raise Errors::NotFoundError, "Couldn't find #{klass} (#{name} was nil)" if raw.nil? return klass.where(by => raw) if raw.is_a?(Array) by == :id ? klass.find(raw) : klass.find_by!(by => raw) end |