lib/riveter/attributes.rb in riveter-0.0.5 vs lib/riveter/attributes.rb in riveter-0.0.6

- old
+ new

@@ -167,22 +167,20 @@ end attr_reader_with_converter name, converter # only add validation of the model instance if supported - if model_or_scope.respond_to?(:valid?) && options[:validate] + if model_or_scope.instance_methods.include?(:valid?) && options[:validate] + validate :"validate_#{name}" - validate :"validate_#{name}_model" - # need a "custom" associated validation since # we don't reference active record... - define_method :"validate_#{name}_model" do + define_method :"validate_#{name}" do instance = self.send(name) return unless required && instance.present? self.errors.add(name, :invalid) unless instance.valid? end - end attr_writer name add_attr(name, :model, converter, options) @@ -392,10 +390,10 @@ enum.values.include?(v) ? v : enum.value_for(v) }.curry[options[:enum]] when :model lambda {|model, attrib, v| - model.find_by(attrib => v) + v.is_a?(model) ? v : model.find_by(attrib => v) }.curry[options[:model], options[:find_by]] else # object etc... lambda {|v| v } end