1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
require 'singleton'
module EmailSpec
class AddressConverter
include Singleton
attr_accessor :converter
# The block provided to conversion should convert to an email
# address string or return the input untouched. For example:
#
# EmailSpec::AddressConverter.instance.conversion do |input|
# if input.is_a?(User)
# input.email
# else
# input
# end
# end
#
def conversion(&block)
self.converter = block
end
def convert(input)
return input unless converter
converter.call(input)
end
end
end
|