lib/surrounded/access_control.rb in surrounded-0.8.4 vs lib/surrounded/access_control.rb in surrounded-0.9.0

- old
+ new

@@ -31,14 +31,14 @@ def define_access_method(name, &block) mod = Module.new mod.class_eval { define_method "disallow_#{name}?" do begin - apply_roles if __apply_role_policy == :trigger + apply_behaviors instance_exec(&block) ensure - remove_roles if __apply_role_policy == :trigger + remove_behaviors end end } const_set("SurroundedAccess#{name}", mod) include mod @@ -55,9 +55,21 @@ def triggers all_triggers.select {|name| method_restrictor = "disallow_#{name}?" !self.respond_to?(method_restrictor, true) || !self.send(method_restrictor) }.to_set + end + + # Ask if the context will allow access to a trigger given the current players. + def allow?(name) + unless self.respond_to?(name) + raise NoMethodError, %{undefined method `#{name}' for #{self.inspect}} + end + if self.respond_to?("disallow_#{name}?") + !self.public_send("disallow_#{name}?") + else + true + end end end end end \ No newline at end of file