Class: PrxAuth::ScopeList
- Inherits:
-
Array
- Object
- Array
- PrxAuth::ScopeList
- Defined in:
- lib/prx_auth/scope_list.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- SCOPE_SEPARATOR =
" "- NAMESPACE_SEPARATOR =
":"- NO_NAMESPACE =
:_
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object
-
#as_json(opts = ()) ⇒ Object
standard:disable Lint/EmptyExpression.
- #condense ⇒ Object
- #contains?(namespace, scope = nil) ⇒ Boolean
-
#initialize(list) ⇒ ScopeList
constructor
A new instance of ScopeList.
- #to_s ⇒ Object
Constructor Details
#initialize(list) ⇒ ScopeList
Returns a new instance of ScopeList.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/prx_auth/scope_list.rb', line 43 def initialize(list) @string = list @string.split(SCOPE_SEPARATOR).uniq.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 |
Class Method Details
.new(list) ⇒ Object
35 36 37 38 39 40 41 |
# 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 end end |
Instance Method Details
#&(other) ⇒ Object
126 127 128 129 130 |
# File 'lib/prx_auth/scope_list.rb', line 126 def &(other) return ScopeList.new("") if other.nil? self - (self - other) + (other - (other - self)) end |
#+(other) ⇒ Object
120 121 122 123 124 |
# File 'lib/prx_auth/scope_list.rb', line 120 def +(other) return self if other.nil? ScopeList.new([to_s, other.to_s].join(SCOPE_SEPARATOR)).condense end |
#-(other) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/prx_auth/scope_list.rb', line 99 def -(other) return self if other.nil? tripped = false result = [] each do |entry| if other.include?(entry) || other.include?(entry.unnamespaced) tripped = true else result << entry end end if tripped ScopeList.new(result.join(SCOPE_SEPARATOR)) else self end end |
#==(other) ⇒ Object
132 133 134 |
# 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 = ()) ⇒ Object
standard:disable Lint/EmptyExpression
95 96 97 |
# File 'lib/prx_auth/scope_list.rb', line 95 def as_json(opts = ()) # standard:disable Lint/EmptyExpression to_s.as_json(opts) end |
#condense ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
72 73 74 |
# File 'lib/prx_auth/scope_list.rb', line 72 def to_s entries.join(SCOPE_SEPARATOR) end |