diff options
author | Samuel Kadolph <samuel@kadolph.com> | 2010-12-09 13:30:02 -0500 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2010-12-16 01:49:28 +0530 |
commit | 972011a2e58be5caf84bf06dd954ba095c823984 (patch) | |
tree | 2018a74e10fd1737a4ef2057c99d6c4b1b189742 /activemodel/lib/active_model | |
parent | 0dc39cd8ee24466f204a292ae61643ce3b3b4c32 (diff) | |
download | rails-972011a2e58be5caf84bf06dd954ba095c823984.tar.gz rails-972011a2e58be5caf84bf06dd954ba095c823984.tar.bz2 rails-972011a2e58be5caf84bf06dd954ba095c823984.zip |
Add support for namespaced validators
Includes test and documentation for new feature
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/validations/validates.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb index 77c5073c6e..0132f68282 100644 --- a/activemodel/lib/active_model/validations/validates.rb +++ b/activemodel/lib/active_model/validations/validates.rb @@ -55,6 +55,10 @@ module ActiveModel # validates :name, :title => true # end # + # Additionally validator classes may be in another namespace and still used within any class. + # + # validates :name, :'file/title' => true + # # The validators hash can also handle regular expressions, ranges, # arrays and strings in shortcut form, e.g. # @@ -86,8 +90,10 @@ module ActiveModel defaults.merge!(:attributes => attributes) validations.each do |key, options| + key = "#{key.to_s.camelize}Validator" + begin - validator = const_get("#{key.to_s.camelize}Validator") + validator = key.include?('::') ? key.constantize : const_get(key) rescue NameError raise ArgumentError, "Unknown validator: '#{key}'" end |