Permalink
Browse files

Merge branch 'release/0.3.2'

  • Loading branch information...
2 parents b06b824 + 6ebec0a commit a4b95269706d7543f1bcbdc39f7e98c9d1e8c29c bokmann committed Jan 6, 2011
Showing with 20 additions and 8 deletions.
  1. +1 −1 VERSION
  2. +14 −4 lib/rails/active_record.rb
  3. +4 −2 lib/stonewall/helpers.rb
  4. +1 −1 lib/stonewall/stonewall.rb
View
@@ -1 +1 @@
-0.3.1
+0.3.2
@@ -5,18 +5,28 @@ def method_missing_with_stonewall(symb, *args)
if method_name =~ /^may_(.+?)[\!\?]$/
guard = $1
if guard.ends_with?("_any")
- guard = guard.gsub("_any", "")
- args.first.any?{ |o| o.class.stonewall.actions[guard.to_sym].call(o, self) }
+ guard = guard.gsub("_any", "").to_sym
+ unless args.first.first.class.stonewall.actions[guard]
+ return method_missing_without_stonewall(symb, *args)
+ end
+ args.first.any?{ |o| o.class.stonewall.actions[guard].call(o, self) }
elsif guard.ends_with?("_all")
- guard = guard.gsub("_all", "")
- args.first.all?{ |o| o.class.stonewall.actions[guard.to_sym].call(o, self) }
+ guard = guard.gsub("_all", "").to_sym
+ unless args.first.first.class.stonewall.actions[guard]
+ return method_missing_without_stonewall(symb, *args)
+ end
+ args.first.all?{ |o| o.class.stonewall.actions[guard].call(o, self) }
else
+ unless args.first.class.stonewall.actions[guard.to_sym]
+ return method_missing_without_stonewall(symb, *args)
+ end
args.first.class.stonewall.actions[guard.to_sym].call(args.first, self)
end
else
method_missing_without_stonewall(symb, *args)
end
end
+
alias_method_chain :method_missing, :stonewall
@@ -7,8 +7,10 @@ def self.symbolize_role(role)
def self.fix_aliases_for(guarded_class)
- guarded_class.stonewall.guarded_methods.each do |m|
- fix_alias_for(guarded_class, m)
+ unless guarded_class.stonewall.nil?
+ guarded_class.stonewall.guarded_methods.each do |m|
+ fix_alias_for(guarded_class, m)
+ end
end
end
@@ -13,7 +13,7 @@ def stonewall()
cattr_accessor :stonewall
self.stonewall = StoneWall::AccessController.new(self)
parser = StoneWall::Parser.new(self)
- yield parser
+ yield parser if block_given?
# if we are being used with acts_as_state_machine (at least, our patched
# version), then we also want the on_transition guards to function as

0 comments on commit a4b9526

Please sign in to comment.