lib/datacaster/predefined.rb in datacaster-3.2.7 vs lib/datacaster/predefined.rb in datacaster-3.3.0

- old
+ new

@@ -274,11 +274,11 @@ result.on(k, v) end end def transform_to_value(value) - transform { value } + transform { Datacaster::Utils.deep_freeze(value) } end def with(keys, caster) keys = Array(keys) @@ -317,10 +317,16 @@ error_keys = ['.float', 'datacaster.errors.float'] error_keys.unshift(error_key) if error_key check { |x| x.is_a?(Float) }.i18n_key(*error_keys) end + def pattern(regexp, error_key = nil) + error_keys = ['.pattern', 'datacaster.errors.pattern'] + error_keys.unshift(error_key) if error_key + string(error_key) & check { |x| x.match?(regexp) }.i18n_key(*error_keys, reference: regexp.inspect) + end + # 'hash' would be a bad method name, because it would override built in Object#hash def hash_value(error_key = nil) error_keys = ['.hash_value', 'datacaster.errors.hash_value'] error_keys.unshift(error_key) if error_key check { |x| x.is_a?(Hash) }.i18n_key(*error_keys) @@ -356,9 +362,15 @@ def non_empty_string(error_key = nil) error_keys = ['.non_empty_string', 'datacaster.errors.non_empty_string'] error_keys.unshift(error_key) if error_key string(error_key) & check { |x| !x.empty? }.i18n_key(*error_keys) + end + + def uuid(error_key = nil) + error_keys = ['.uuid', 'datacaster.errors.uuid'] + error_keys.unshift(error_key) if error_key + string(error_key) & pattern(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/).i18n_key(*error_keys) end # Form request types def iso8601(error_key = nil)