Freeze options so we raise an error when people modify it in place.

This commit is contained in:
José Valim
2010-08-03 15:34:31 +02:00
parent 79583ca9b1
commit 3b170b2e14
2 changed files with 5 additions and 3 deletions

View File

@@ -118,11 +118,13 @@ module ActiveModel
# end
#
def validate(*args, &block)
options = args.last
if options.is_a?(Hash) && options.key?(:on)
options = args.extract_options!
if options.key?(:on)
options = options.dup
options[:if] = Array.wrap(options[:if])
options[:if] << "validation_context == :#{options[:on]}"
end
args << options
set_callback(:validate, *args, &block)
end

View File

@@ -111,7 +111,7 @@ module ActiveModel #:nodoc:
# Accepts options that will be made available through the +options+ reader.
def initialize(options)
@options = options
@options = options.freeze
end
# Return the kind for this validator.