Class: Operations::Components::Policies
- Defined in:
- lib/operations/components/policies.rb
Overview
We are looking for the first policy failure to return because it does not make sense to check for all policy failures. One is more than enough to know that we are not allowed to call the operation.
If policy returns ‘false` then generic `:unauthorized` error code will be used. In case of `Failure` monad - the error code depends on the failure internal value. It can be a String, Symbol or even a Hash containing `:error` key.
Successful policies return either ‘true` or `Success` monad.
Constant Summary
Constants inherited from Base
Base::DEFAULT_NAMES_MAP, Base::MONADS_DO_WRAPPER_SIGNATURES
Instance Method Summary collapse
Methods inherited from Prechecks
Instance Method Details
#call(params, context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/operations/components/policies.rb', line 16 def call(params, context) first_failure = callable.lazy.filter_map do |entry| result_failure(entry.call(**context), entry) end.first result( params: params, context: context, errors: errors(normalize_failure([first_failure].compact)) ) end |