Permalink
Browse files

AccessibleFor: renamed accessible_attributes due to activerecord conf…

…licts
  • Loading branch information...
1 parent 9a368b5 commit 44b116c49ceae23a7d6ce6be8561eb2885820972 @zenhob committed Mar 8, 2012
Showing with 11 additions and 11 deletions.
  1. +3 −3 README.markdown
  2. +6 −6 lib/accessible_for.rb
  3. +1 −1 lib/mass_assignment_backport.rb
  4. +1 −1 test/accessible_for_test.rb
View
@@ -38,10 +38,10 @@ accessible_for API (to avoid name conflicts).
accessible_for :manager => :promotion
# If that's not DRY enough you can compose access lists from other roles
- # using the class method accessible_attributes
+ # using the class method accessible_by
accessible_for :common => [ :filling, :topping ]
- accessible_for :customer => accessible_attributes(:common) + [ :rating ]
- accessible_for :manager => accessible_attributes(:common) + [ :price, :promotion ]
+ accessible_for :customer => accessible_by(:common) + [ :rating ]
+ accessible_for :manager => accessible_by(:common) + [ :price, :promotion ]
def update
Taco.find(params[:id]).update_attributes!(taco_params)
View
@@ -8,27 +8,27 @@ def self.included(mod)
end
module ClassMethods
- attr_accessor :_accessible_attributes
+ attr_accessor :_accessible_by
def accessible_for params
params.each do |role, attrs|
- self._accessible_attributes ||= {}
+ self._accessible_by ||= {}
[role].flatten.each do |name|
- self._accessible_attributes[name] = accessible_attributes(name) + [attrs].flatten
+ self._accessible_by[name] = accessible_by(name) + [attrs].flatten
end
end
end
- def accessible_attributes role
- _accessible_attributes && _accessible_attributes[role] || []
+ def accessible_by role
+ _accessible_by && _accessible_by[role] || []
end
end
def sanitize_for role, values
return nil if values.nil?
result = block_given? ? nil : {}
values.each do |k, v|
- if self.class.accessible_attributes(role).include?(k.to_sym)
+ if self.class.accessible_by(role).include?(k.to_sym)
if block_given?
yield k, v
else
@@ -12,7 +12,7 @@ def attr_accessible *args
end
def accessible_attributes role=:default
- super role
+ accessible_by role
end
end
@@ -3,7 +3,7 @@
class AccessibleForTest < MiniTest::Unit::TestCase
include AccessibleFor
accessible_for :default => :topping
- accessible_for :manager => accessible_attributes(:default) + [:price]
+ accessible_for :manager => accessible_by(:default) + [:price]
def test_nil_params
assert_nil sanitize_for(:default, nil)

0 comments on commit 44b116c

Please sign in to comment.