Module: LightService::ValidatedContext::KeyVerifier
- Included in:
- Context::KeyVerifier
- Defined in:
- lib/light_service/validated_context/key_verifier.rb
Instance Method Summary collapse
-
#are_all_keys_valid? ⇒ Boolean
rubocop:enable Metrics/AbcSize.
- #error_message ⇒ Object
- #initialize(context, action) ⇒ Object
- #should_throw_on_validation_error? ⇒ Boolean
-
#type_check_and_coerce_keys!(keys) ⇒ Object
rubocop:disable Metrics/AbcSize Refactoring this is out of my scope ATM.
Instance Method Details
#are_all_keys_valid? ⇒ Boolean
rubocop:enable Metrics/AbcSize
34 35 36 |
# File 'lib/light_service/validated_context/key_verifier.rb', line 34 def are_all_keys_valid? @validation_errors.none? end |
#error_message ⇒ Object
38 39 40 |
# File 'lib/light_service/validated_context/key_verifier.rb', line 38 def @validation_errors.join(', ') end |
#initialize(context, action) ⇒ Object
6 7 8 9 10 |
# File 'lib/light_service/validated_context/key_verifier.rb', line 6 def initialize(context, action) @validation_errors = [] super(context, action) end |
#should_throw_on_validation_error? ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/light_service/validated_context/key_verifier.rb', line 42 def should_throw_on_validation_error? return true unless action.respond_to?(:fail_on_validation_error?) && action.fail_on_validation_error? context.fail!() false end |
#type_check_and_coerce_keys!(keys) ⇒ Object
rubocop:disable Metrics/AbcSize Refactoring this is out of my scope ATM
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/light_service/validated_context/key_verifier.rb', line 14 def type_check_and_coerce_keys!(keys) errors = [] keys.each do |key| next unless key.is_a?(LightService::Context::ValidatedKey) begin context[key.label] = key.type[context[key.label] || Dry::Types::Undefined] rescue Dry::Types::CoercionError => e errors << ( LightService::Configuration.localization_adapter.failure(key., action) || "[#{action}][:#{key.label}] #{e.}" ) end end @validation_errors = errors end |