class Aclize::Acl::PathsRegistry
Attributes
denied[R]
permitted[R]
Public Class Methods
new()
click to toggle source
# File lib/aclize/acl/paths_registry.rb, line 13 def initialize @permitted = [] @denied = [] end
Public Instance Methods
denied?(*args)
click to toggle source
Check if any of the paths is explicitly denied
# File lib/aclize/acl/paths_registry.rb, line 61 def denied?(*args) @denied.each do |denied_path| args.flatten.each do |path| return true if path.match(/^#{denied_path}$/) end end return false end
deny(*paths)
click to toggle source
deny a path
# File lib/aclize/acl/paths_registry.rb, line 27 def deny(*paths) @denied += normalize(paths) @denied.uniq! end
permit(*paths)
click to toggle source
permit a new path
# File lib/aclize/acl/paths_registry.rb, line 20 def permit(*paths) @permitted += normalize(paths) @permitted.uniq! end
permitted?(*args)
click to toggle source
Check if the paths are permitted. This method should return true only if each path passed as argument is permitted (isn't denied and have an explicit permission).
# File lib/aclize/acl/paths_registry.rb, line 36 def permitted?(*args) permitted = false return false if denied?(args) # each path should have an explicit permission in order to return true args.flatten.each do |path| # we assume that the path isn't permitted permitted = false # iterate over permitted paths and check if any of them matches the current one @permitted.each do |permitted_path| permitted ||= !!path.match(/^#{permitted_path}$/) # stop iteration if the path is permitted break if permitted end #return false if the path isn't permitted return false unless permitted end return permitted end
Protected Instance Methods
normalize(items)
click to toggle source
# File lib/aclize/acl/paths_registry.rb, line 73 def normalize(items) return items.nil? ? [] : items.is_a?(Array) ? items.flatten : [items] end