class PrxAuth::ScopeList

Constants

Entry
NAMESPACE_SEPARATOR
NO_NAMESPACE
SCOPE_SEPARATOR

Public Class Methods

new(list) click to toggle source
Calls superclass method
# File lib/prx_auth/scope_list.rb, line 35
def self.new(list)
  case list
  when PrxAuth::ScopeList then list
  when Array then super(list.join(' '))
  else super(list)
  end
end
new(list) click to toggle source
# File lib/prx_auth/scope_list.rb, line 43
def initialize(list)
  @string = list
  @string.split(SCOPE_SEPARATOR).each do |value|
    next if value.length < 1

    parts = value.split(NAMESPACE_SEPARATOR, 2)
    if parts.length == 2
      push Entry.new(symbolize(parts[0]), symbolize(parts[1]), value)
    else
      push Entry.new(NO_NAMESPACE, symbolize(parts[0]), value)
    end
  end
end

Public Instance Methods

&(other_list) click to toggle source
# File lib/prx_auth/scope_list.rb, line 126
def &(other_list)
  return ScopeList.new('') if other_list.nil?
  
  self - (self - other_list) + (other_list - (other_list - self))
end
+(other_list) click to toggle source
# File lib/prx_auth/scope_list.rb, line 120
def +(other_list)
  return self if other_list.nil?

  ScopeList.new([to_s, other_list.to_s].join(SCOPE_SEPARATOR)).condense
end
-(other_scope_list) click to toggle source
# File lib/prx_auth/scope_list.rb, line 99
def -(other_scope_list)
  return self if other_scope_list.nil?

  tripped = false
  result = []

  each do |entry|
    if other_scope_list.include?(entry) || other_scope_list.include?(entry.unnamespaced)
      tripped = true
    else
      result << entry
    end
  end

  if tripped
    ScopeList.new(result.join(SCOPE_SEPARATOR))
  else
    self
  end
end
==(other) click to toggle source
# File lib/prx_auth/scope_list.rb, line 132
def ==(other)
  condense.sort_by(&:to_s) == other.condense.sort_by(&:to_s)
end
as_json(opts=()) click to toggle source
# File lib/prx_auth/scope_list.rb, line 95
def as_json(opts=())
  to_s.as_json(opts)
end
condense() click to toggle source
# File lib/prx_auth/scope_list.rb, line 76
def condense
  tripped = false
  result = []

  each do |entry|
    if entry.namespaced? && include?(entry.unnamespaced)
      tripped = true
    else
      result << entry
    end
  end

  if tripped
    ScopeList.new(result.join(SCOPE_SEPARATOR))
  else
    self
  end
end
contains?(namespace, scope=nil) click to toggle source
# File lib/prx_auth/scope_list.rb, line 57
def contains?(namespace, scope=nil)
  entries = if scope.nil?
              scope, namespace = namespace, NO_NAMESPACE 
              [Entry.new(namespace, symbolize(scope), nil)]
            else
              scope = symbolize(scope)
              namespace = symbolize(namespace)
              [Entry.new(namespace, scope, nil), Entry.new(NO_NAMESPACE, scope, nil)]
            end
  
  entries.any? do |possible_match|
    include?(possible_match)
  end
end
to_s() click to toggle source
# File lib/prx_auth/scope_list.rb, line 72
def to_s
  @string
end

Private Instance Methods

symbolize(value) click to toggle source
# File lib/prx_auth/scope_list.rb, line 138
def symbolize(value)
  case value
  when Symbol then value
  when String then value.downcase.gsub('-', '_').intern
  else symbolize value.to_s
  end
end