Sha256: a0affc6834fdea6903d407a1dc6bb7d0a653923d2b3fb33a0686d5471d38198b
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
module Compel module Builder module Common def is(value, options = {}) build_option :is, Coercion.coerce!(value, self.type), options end def required(options = {}) build_option :required, true, options end def default(value, options = {}) build_option :default, Coercion.coerce!(value, self.type), options end def length(value, options = {}) build_option :length, Coercion.coerce!(value, Coercion::Integer), options end def min_length(value, options = {}) build_option :min_length, Coercion.coerce!(value, Coercion::Integer), options end def max_length(value, options = {}) build_option :max_length, Coercion.coerce!(value, Coercion::Integer), options end def if(lambda = nil, options = {}, &block) build_option :if, coerce_if_proc(lambda || block), options rescue raise Compel::TypeError, 'invalid proc for if' end # this is lovely, refactor later def coerce_if_proc(proc) if proc && proc.is_a?(Proc) && (proc.arity == 1 || proc.arity == 0 && (proc.call.is_a?(::Symbol) || proc.call.is_a?(::String))) proc else fail end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
compel-0.5.1 | lib/compel/builder/common.rb |
compel-0.5.0 | lib/compel/builder/common.rb |
compel-0.4.3 | lib/compel/builder/common.rb |