class PrxAuth::ResourceMap
Constants
- WILDCARD_KEY
Public Class Methods
new(mapped_values)
click to toggle source
Calls superclass method
# File lib/prx_auth/resource_map.rb, line 5 def initialize(mapped_values) super() do |hash, key| if key == WILDCARD_KEY @wildcard else nil end end input = mapped_values.clone @wildcard = ScopeList.new(input.delete(WILDCARD_KEY)||'') input.each do |(key, values)| self[key.to_s] = ScopeList.new(values) end end
Public Instance Methods
&(other_map)
click to toggle source
# File lib/prx_auth/resource_map.rb, line 88 def &(other_map) result = {} other_wildcard = other_map.list_for_resource(WILDCARD_KEY) (resources + other_map.resources).uniq.each do |res| left = list_for_resource(res) right = other_map.list_for_resource(res) result[res] = if left.nil? right & @wildcard elsif right.nil? left & other_wildcard else (left + @wildcard) & (right + other_wildcard) end end if @wildcard.length > 0 result[WILDCARD_KEY] = @wildcard - (@wildcard - other_wildcard) end ResourceMap.new(result).condense end
+(other_map)
click to toggle source
# File lib/prx_auth/resource_map.rb, line 56 def +(other_map) result = {} (resources + other_map.resources + [WILDCARD_KEY]).uniq.each do |resource| list_a = list_for_resource(resource) list_b = other_map.list_for_resource(resource) result[resource] = if list_a.nil? list_b elsif list_b.nil? list_a else list_a + list_b end end ResourceMap.new(result).condense end
-(other_map)
click to toggle source
# File lib/prx_auth/resource_map.rb, line 73 def -(other_map) result = {} other_wildcard = other_map.list_for_resource(WILDCARD_KEY) || PrxAuth::ScopeList.new('') resources.each do |resource| result[resource] = list_for_resource(resource) - (other_wildcard + other_map.list_for_resource(resource)) end if @wildcard.length result[WILDCARD_KEY] = @wildcard - other_wildcard end ResourceMap.new(result) end
[](key)
click to toggle source
Calls superclass method
# File lib/prx_auth/resource_map.rb, line 40 def [](key) super(key.to_s) end
[]=(key, value)
click to toggle source
Calls superclass method
# File lib/prx_auth/resource_map.rb, line 44 def []=(key, value) super(key.to_s, value) end
as_json(opts={})
click to toggle source
Calls superclass method
# File lib/prx_auth/resource_map.rb, line 112 def as_json(opts={}) super(opts).merge(@wildcard.length > 0 ? {WILDCARD_KEY => @wildcard}.as_json(opts) : {}) end
condense()
click to toggle source
# File lib/prx_auth/resource_map.rb, line 48 def condense condensed_wildcard = @wildcard.condense condensed_map = Hash[map do |resource, list| [resource, (list - condensed_wildcard).condense] end] ResourceMap.new(condensed_map.merge(WILDCARD_KEY => condensed_wildcard)) end
contains?(resource, namespace=nil, scope=nil)
click to toggle source
# File lib/prx_auth/resource_map.rb, line 20 def contains?(resource, namespace=nil, scope=nil) resource = resource.to_s if resource == WILDCARD_KEY raise ArgumentError if namespace.nil? @wildcard.contains?(namespace, scope) else mapped_resource = self[resource] if mapped_resource && !namespace.nil? mapped_resource.contains?(namespace, scope) || @wildcard.contains?(namespace, scope) elsif !namespace.nil? @wildcard.contains?(namespace, scope) else !!mapped_resource end end end
resources(namespace=nil, scope=nil)
click to toggle source
# File lib/prx_auth/resource_map.rb, line 116 def resources(namespace=nil, scope=nil) if namespace.nil? keys else select do |name, list| list.contains?(namespace, scope) || @wildcard.contains?(namespace, scope) end.map(&:first) end end
Protected Instance Methods
list_for_resource(resource)
click to toggle source
# File lib/prx_auth/resource_map.rb, line 128 def list_for_resource(resource) self[resource.to_s] end