Module: Compel::Builder::Common
- Included in:
- Schema
- Defined in:
- lib/compel/builder/common.rb
Instance Method Summary collapse
-
#coerce_if_proc(proc) ⇒ Object
this is lovely, refactor later.
- #default(value, options = {}) ⇒ Object
- #if(lambda = nil, options = {}, &block) ⇒ Object
- #is(value, options = {}) ⇒ Object
- #length(value, options = {}) ⇒ Object
- #max_length(value, options = {}) ⇒ Object
- #min_length(value, options = {}) ⇒ Object
- #required(options = {}) ⇒ Object
Instance Method Details
#coerce_if_proc(proc) ⇒ Object
this is lovely, refactor later
38 39 40 41 42 43 44 45 46 |
# File 'lib/compel/builder/common.rb', line 38 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 |
#default(value, options = {}) ⇒ Object
14 15 16 |
# File 'lib/compel/builder/common.rb', line 14 def default(value, = {}) build_option :default, Coercion.coerce!(value, self.type), end |
#if(lambda = nil, options = {}, &block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/compel/builder/common.rb', line 30 def if(lambda = nil, = {}, &block) build_option :if, coerce_if_proc(lambda || block), rescue raise Compel::TypeError, 'invalid proc for if' end |
#is(value, options = {}) ⇒ Object
6 7 8 |
# File 'lib/compel/builder/common.rb', line 6 def is(value, = {}) build_option :is, Coercion.coerce!(value, self.type), end |
#length(value, options = {}) ⇒ Object
18 19 20 |
# File 'lib/compel/builder/common.rb', line 18 def length(value, = {}) build_option :length, Coercion.coerce!(value, Coercion::Integer), end |
#max_length(value, options = {}) ⇒ Object
26 27 28 |
# File 'lib/compel/builder/common.rb', line 26 def max_length(value, = {}) build_option :max_length, Coercion.coerce!(value, Coercion::Integer), end |
#min_length(value, options = {}) ⇒ Object
22 23 24 |
# File 'lib/compel/builder/common.rb', line 22 def min_length(value, = {}) build_option :min_length, Coercion.coerce!(value, Coercion::Integer), end |
#required(options = {}) ⇒ Object
10 11 12 |
# File 'lib/compel/builder/common.rb', line 10 def required( = {}) build_option :required, true, end |