Sha256: 73170f9b277853ad850e1199dbb2dbd4a19639a72c99bf5cfd61202ed5bb01f1
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module Surrounded module AccessControl def self.extended(base) base.send(:include, AccessMethods) end private def disallow(*names, &block) names.map do |name| define_method("disallow_#{name}?", &block) end end 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 ::Surrounded::Context::AccessError.new("access to `#{name}' is not allowed") end self.send("__trigger_#{name}") ensure remove_roles if __apply_role_policy == :trigger end end } end module AccessMethods def all_triggers self.class.triggers end def triggers all_triggers.select {|name| method_restrictor = "disallow_#{name}?" !self.respond_to?(method_restrictor, true) || !self.send(method_restrictor) }.to_set end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
surrounded-0.7.0 | lib/surrounded/access_control.rb |