class FunctionalLightService::Context::KeyVerifier

Attributes

action[R]
context[R]

Public Class Methods

new(context, action) click to toggle source
# File lib/functional-light-service/context/key_verifier.rb, line 6
def initialize(context, action)
  @context = context
  @action = action
end
verify_keys(context, action, &block) click to toggle source
# File lib/functional-light-service/context/key_verifier.rb, line 45
def self.verify_keys(context, action, &block)
  ReservedKeysVerifier.new(context, action).verify
  ExpectedKeyVerifier.new(context, action).verify

  block.call

  PromisedKeyVerifier.new(context, action).verify
end

Public Instance Methods

are_all_keys_in_context?(keys) click to toggle source
# 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() click to toggle source
# 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
format_keys(keys) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
verify() click to toggle source
# 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