Permalink
Browse files

Reduce complexity in MassAssignmentSecurity

  • Loading branch information...
1 parent 5f330be commit 6ed0eca9709bda85e666f22c18bb63f7b04b3c0b @cgriego committed Jul 11, 2012
Showing with 14 additions and 7 deletions.
  1. +14 −7 lib/active_attr/mass_assignment_security.rb
@@ -32,16 +32,23 @@ module MassAssignmentSecurity
# @since 0.3.0
def assign_attributes(new_attributes, options={})
if new_attributes && !options[:without_protection]
- if method(:sanitize_for_mass_assignment).arity.abs > 1
- mass_assignment_role = options[:as] || :default
- new_attributes = sanitize_for_mass_assignment new_attributes, mass_assignment_role
- else
- # Rails 3.0 has no roles support in mass assignment
- new_attributes = sanitize_for_mass_assignment new_attributes
- end
+ mass_assignment_role = options[:as] || :default
+ new_attributes = sanitize_for_mass_assignment_with_or_without_role new_attributes, mass_assignment_role
end
super
end
+
+ private
+
+ # Rails 3.0 has no roles support in mass assignment
+ # @since 0.7.0
+ def sanitize_for_mass_assignment_with_or_without_role(new_attributes, mass_assignment_role)
+ if method(:sanitize_for_mass_assignment).arity.abs > 1
+ sanitize_for_mass_assignment new_attributes, mass_assignment_role
+ else
+ sanitize_for_mass_assignment new_attributes
+ end
+ end
end
end

0 comments on commit 6ed0eca

Please sign in to comment.