From 209e36f61be9eb81ccffd86376d9e1302051ca4a Mon Sep 17 00:00:00 2001 From: Seth Ladd Date: Mon, 8 Jun 2009 16:35:26 -1000 Subject: [PATCH] cast values through setters to ensure validations are run after mass assignment, for example --- lib/couchrest/mixins/properties.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index 953e125..e7a6303 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -114,9 +114,13 @@ module CouchRest if #{property.casted} && value.is_a?(Array) arr = CastedArray.new arr.casted_by = self - value.each { |v| arr << v } + value.each do |v| + obj = #{property.type}.new(v) + arr << obj + end value = arr elsif #{property.casted} + value = #{property.type}.new(v) value.casted_by = self if value.respond_to?(:casted_by) end self['#{meth}'] = value