Class: CleanArchitecture::UseCases::Parameters
- Inherits:
-
Object
- Object
- CleanArchitecture::UseCases::Parameters
- Extended by:
- Forwardable
- Includes:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/clean_architecture/use_cases/parameters.rb
Constant Summary collapse
- INVALID_PARAMS_FAILURE_TYPE =
'expectation_failed'
Instance Method Summary collapse
- #context(key) ⇒ Object
- #errors ⇒ Object
-
#initialize(context, dry_validation_result) ⇒ Parameters
constructor
A new instance of Parameters.
- #to_monad ⇒ Object
Constructor Details
#initialize(context, dry_validation_result) ⇒ Parameters
Returns a new instance of Parameters.
13 14 15 16 |
# File 'lib/clean_architecture/use_cases/parameters.rb', line 13 def initialize(context, dry_validation_result) @context = context @dry_validation_result = dry_validation_result end |
Instance Method Details
#context(key) ⇒ Object
18 19 20 |
# File 'lib/clean_architecture/use_cases/parameters.rb', line 18 def context(key) @context.fetch(key) end |
#errors ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/clean_architecture/use_cases/parameters.rb', line 31 def errors new_errors = Errors.new(nil, INVALID_PARAMS_FAILURE_TYPE) @dry_validation_result.errors.to_h.each_pair do |invalid_attribute_key, | .each do || new_errors.add(invalid_attribute_key, ) end end new_errors end |
#to_monad ⇒ Object
25 26 27 |
# File 'lib/clean_architecture/use_cases/parameters.rb', line 25 def to_monad @dry_validation_result.success? ? Success(@dry_validation_result.to_h) : Failure(errors) end |