Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reduce complexity in MassAssignmentSecurity

  • Loading branch information...
commit 6ed0eca9709bda85e666f22c18bb63f7b04b3c0b 1 parent 5f330be
@cgriego authored
Showing with 14 additions and 7 deletions.
  1. +14 −7 lib/active_attr/mass_assignment_security.rb
View
21 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
Please sign in to comment.
Something went wrong with that request. Please try again.