module Environmentor::TypeCoercer
Public Instance Methods
coerce_to(type, val)
click to toggle source
# File lib/environmentor/type_coercer.rb, line 7 def coerce_to(type, val) coercer = type_coercers[type] or raise UnknownType, type coercer.call val end
register_type(*type_names, &block)
click to toggle source
# File lib/environmentor/type_coercer.rb, line 17 def register_type(*type_names, &block) raise ArgumentError, "No type names given" if type_names.empty? raise ArgumentError, "No block given" unless block_given? raise ArgumentError, "Block should have arity of 1, taking value to coerce" unless block.arity == 1 type_names.each do |tn| type_coercers[tn] = block end nil end
valid_type?(type)
click to toggle source
# File lib/environmentor/type_coercer.rb, line 13 def valid_type?(type) type_coercers.keys.include? type end
Private Instance Methods
type_coercers()
click to toggle source
# File lib/environmentor/type_coercer.rb, line 30 def type_coercers @type_coercers ||= {} end