module ErrandBoy module Validator class Base def initialize(request) @request = request end def run methods.each do |method| send(method) if /check_\w+/ === method end end def check_sender_name warn 'sender_name is empty.' if @request.sender['name'].empty? rescue NoMethodError warn 'sender does not set.' end def check_sender_email email = @request.sender['email'] if email.empty? warn 'sender_email is empty.' elsif email !~ valid_address warn 'sender_email is invalid address.' end rescue NoMethodError warn 'sender does not set.' end def valid_address %r(\A[a-zA-Z0-9_\#!$%&`'*+\-{|}~^\/=?\.]+@[a-zA-Z0-9][a-zA-Z0-9\.-]+\z) end end end end