Module: Compel::Builder::CommonValue
- Defined in:
- lib/compel/builder/common_value.rb
Instance Method Summary collapse
- #coerce_value!(value, method) ⇒ Object
- #coerce_values_ary!(values, method) ⇒ Object
- #in(value, options = {}) ⇒ Object
- #max(value, options = {}) ⇒ Object
- #min(value, options = {}) ⇒ Object
- #raise_array_error(method) ⇒ Object
- #raise_array_values_error(method) ⇒ Object
- #raise_value_error(method) ⇒ Object
- #range(value, options = {}) ⇒ Object
Instance Method Details
#coerce_value!(value, method) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/compel/builder/common_value.rb', line 37 def coerce_value!(value, method) begin fail if value.nil? Coercion.coerce!(value, self.type) rescue raise_value_error(method) end end |
#coerce_values_ary!(values, method) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/compel/builder/common_value.rb', line 22 def coerce_values_ary!(values, method) begin fail if values.nil? Coercion.coerce!(values, Coercion::Array) rescue raise_array_error(method) end values.map{ |value| Coercion.coerce!(value, self.type) } rescue raise_array_values_error(method) end |
#in(value, options = {}) ⇒ Object
6 7 8 |
# File 'lib/compel/builder/common_value.rb', line 6 def in(value, = {}) build_option :in, coerce_values_ary!(value, :in), end |
#max(value, options = {}) ⇒ Object
18 19 20 |
# File 'lib/compel/builder/common_value.rb', line 18 def max(value, = {}) build_option :max, coerce_value!(value, :max), end |
#min(value, options = {}) ⇒ Object
14 15 16 |
# File 'lib/compel/builder/common_value.rb', line 14 def min(value, = {}) build_option :min, coerce_value!(value, :min), end |
#raise_array_error(method) ⇒ Object
47 48 49 50 |
# File 'lib/compel/builder/common_value.rb', line 47 def raise_array_error(method) raise TypeError, "#{self.class.human_name} ##{method} " \ "value must an Array" end |
#raise_array_values_error(method) ⇒ Object
52 53 54 55 |
# File 'lib/compel/builder/common_value.rb', line 52 def raise_array_values_error(method) raise TypeError, "All #{self.class.human_name} ##{method} values " \ "must be a valid #{self.type.human_name}" end |
#raise_value_error(method) ⇒ Object
57 58 59 60 |
# File 'lib/compel/builder/common_value.rb', line 57 def raise_value_error(method) raise TypeError, "#{self.class.human_name} ##{method} value " \ "must be a valid #{self.type.human_name}" end |
#range(value, options = {}) ⇒ Object
10 11 12 |
# File 'lib/compel/builder/common_value.rb', line 10 def range(value, = {}) build_option :range, coerce_values_ary!(value, :range), end |