Class: OmniService::FindOne
- Inherits:
-
Object
- Object
- OmniService::FindOne
- Extended by:
- Dry::Initializer
- Defined in:
- lib/omni_service/find_one.rb
Overview
Finds a single entity by ID or attributes via repository#get_one. Skips lookup if entity already exists in context.
Options:
-
:with - param key for lookup (default: :“#context_key_id”)
-
:by - column mapping, supports nested paths: { id: [:deep, :post_id] }
-
:repository - single repo or Hash for polymorphic lookup
-
:type - path to type discriminator for polymorphic lookup
Flags:
-
:nullable - allow nil param value, returns Success(key: nil)
-
:omittable - allow missing param key, returns Success({})
-
:skippable - return Success({}) when entity not found instead of Failure
Constant Summary collapse
- PRIMARY_KEY =
:id
Instance Method Summary collapse
Instance Method Details
#call(params, **context) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/omni_service/find_one.rb', line 69 def call(params, **context) return Success({}) if already_found?(context) missing_keys = missing_keys(params, pointers) return missing_keys_result(missing_keys, context) unless missing_keys.empty? values = values(params) return Success(context_key => nil) if nullable && values.all?(&:nil?) repository = resolve_repository(params) return repository_failure(params, values) unless repository find(values, repository:) end |