lib/surrounded/access_control.rb in surrounded-0.8.2 vs lib/surrounded/access_control.rb in surrounded-0.8.3

- old
+ new

@@ -12,29 +12,22 @@ def disallow(*names, &block) names.map do |name| define_access_method(name, &block) end end + alias_method :guard, :disallow - def redo_method(name) - class_eval %{ - def #{name} - begin - apply_roles if __apply_role_policy == :trigger - - method_restrictor = "disallow_#{name}?" - if self.respond_to?(method_restrictor, true) && self.send(method_restrictor) - raise ::#{self.to_s}::AccessError.new("access to #{self.name}##{name} is not allowed") - end - - #{trigger_return_content(name)} + def trigger_return_content(name) + %{ - ensure - remove_roles if __apply_role_policy == :trigger - end + method_restrictor = "disallow_#{name}?" + if self.respond_to?(method_restrictor, true) && self.send(method_restrictor) + raise ::#{self.to_s}::AccessError.new("access to #{self.name}##{name} is not allowed") end - }, __FILE__, __LINE__ + + #{super} + } end def define_access_method(name, &block) class_eval { define_method "disallow_#{name}?" do @@ -47,13 +40,16 @@ end } end module AccessMethods + # Return a Set of all defined triggers regardless of any disallow blocks def all_triggers self.class.triggers end + # Return a Set of triggers which may be run according to any restrictions defined + # in disallow blocks. def triggers all_triggers.select {|name| method_restrictor = "disallow_#{name}?" !self.respond_to?(method_restrictor, true) || !self.send(method_restrictor) }.to_set \ No newline at end of file