module NRSER::NicerError::ClassMethods

Public Instance Methods

def_context_delegator(keys:, presence_predicate: true) click to toggle source
# File lib/nrser/errors/nicer_error.rb, line 51
def def_context_delegator keys:, presence_predicate: true
  keys = Array keys

  keys.each do |key|
    define_method key do
      if (found_key = keys.find { |k| context.key? k })
        context[found_key]
      end
    end

    if presence_predicate
      define_method "#{ key }?" do
        !!keys.find { |k| context.key? k }
      end
    end
  end
end