Class: FunctionalLightService::Context::KeyVerifier
- Inherits:
-
Object
- Object
- FunctionalLightService::Context::KeyVerifier
show all
- Defined in:
- lib/functional-light-service/context/key_verifier.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, action) ⇒ KeyVerifier
Returns a new instance of KeyVerifier.
6
7
8
9
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 6
def initialize(context, action)
@context = context
@action = action
end
|
Instance Attribute Details
Returns the value of attribute action.
4
5
6
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 4
def action
@action
end
|
Returns the value of attribute context.
4
5
6
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 4
def context
@context
end
|
Class Method Details
.verify_keys(context, action, &block) ⇒ Object
Instance Method Details
#are_all_keys_in_context?(keys) ⇒ Boolean
11
12
13
14
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 11
def are_all_keys_in_context?(keys)
not_found_keys = keys_not_found(keys)
not_found_keys.none?
end
|
#error_message ⇒ Object
25
26
27
28
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 25
def error_message
"#{type_name} #{format_keys(keys_not_found(keys))} " \
"to be in the context during #{action}"
end
|
21
22
23
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 21
def format_keys(keys)
keys.map { |k| ":#{k}" }.join(', ')
end
|
#keys_not_found(keys) ⇒ Object
16
17
18
19
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 16
def keys_not_found(keys)
keys ||= context.keys
keys - context.keys
end
|
#throw_error_predicate(_keys) ⇒ Object
30
31
32
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 30
def throw_error_predicate(_keys)
raise NotImplementedError, 'Sorry, you have to override length'
end
|
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/functional-light-service/context/key_verifier.rb', line 34
def verify
return context if context.failure?
if throw_error_predicate(keys)
Configuration.logger.error error_message
raise error_to_throw, error_message
end
context
end
|