diff options
author | José Valim <jose.valim@gmail.com> | 2012-03-16 13:40:42 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-03-16 13:40:42 +0100 |
commit | 034ccf40489d5329ac72a0a5d33b907f755cf1b6 (patch) | |
tree | 63cc91dabb8cd7fb3e4cf115dc56f87406009ace /activemodel | |
parent | 6d0047aff8b7c333625d3a4b97dfa3e8a63588e2 (diff) | |
download | rails-034ccf40489d5329ac72a0a5d33b907f755cf1b6.tar.gz rails-034ccf40489d5329ac72a0a5d33b907f755cf1b6.tar.bz2 rails-034ccf40489d5329ac72a0a5d33b907f755cf1b6.zip |
Speed up mass assignment by avoiding extra loops.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/mass_assignment_security/sanitizer.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb b/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb index cfeb4aa7cd..4491e07a72 100644 --- a/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb +++ b/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb @@ -3,18 +3,16 @@ module ActiveModel class Sanitizer # Returns all attributes not denied by the authorizer. def sanitize(attributes, authorizer) - sanitized_attributes = attributes.reject { |key, value| authorizer.deny?(key) } - debug_protected_attribute_removal(attributes, sanitized_attributes) + rejected = [] + sanitized_attributes = attributes.reject do |key, value| + rejected << key if authorizer.deny?(key) + end + process_removed_attributes(rejected) unless rejected.empty? sanitized_attributes end protected - def debug_protected_attribute_removal(attributes, sanitized_attributes) - removed_keys = attributes.keys - sanitized_attributes.keys - process_removed_attributes(removed_keys) if removed_keys.any? - end - def process_removed_attributes(attrs) raise NotImplementedError, "#process_removed_attributes(attrs) suppose to be overwritten" end |