Class: Doorkeeper::OAuth::Scopes

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/doorkeeper/oauth/scopes.rb

Constant Summary collapse

DYNAMIC_SCOPE_WILDCARD =
"*"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScopes

Returns a new instance of Scopes.



26
27
28
# File 'lib/doorkeeper/oauth/scopes.rb', line 26

def initialize
  @scopes = []
end

Class Method Details

.from_array(array) ⇒ Object



18
19
20
21
22
# File 'lib/doorkeeper/oauth/scopes.rb', line 18

def self.from_array(array)
  new.tap do |scope|
    scope.add(*array)
  end
end

.from_string(string) ⇒ Object



11
12
13
14
15
16
# File 'lib/doorkeeper/oauth/scopes.rb', line 11

def self.from_string(string)
  string ||= ""
  new.tap do |scope|
    scope.add(*string.split)
  end
end

Instance Method Details

#&(other) ⇒ Object



73
74
75
# File 'lib/doorkeeper/oauth/scopes.rb', line 73

def &(other)
  self.class.from_array(all & to_array(other))
end

#+(other) ⇒ Object



61
62
63
# File 'lib/doorkeeper/oauth/scopes.rb', line 61

def +(other)
  self.class.from_array(all + to_array(other))
end

#<=>(other) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/doorkeeper/oauth/scopes.rb', line 65

def <=>(other)
  if other.respond_to?(:map)
    map(&:to_s).sort <=> other.map(&:to_s).sort
  else
    super
  end
end

#add(*scopes) ⇒ Object



42
43
44
45
# File 'lib/doorkeeper/oauth/scopes.rb', line 42

def add(*scopes)
  @scopes.push(*scopes.map(&:to_s))
  @scopes.uniq!
end

#allObject



47
48
49
# File 'lib/doorkeeper/oauth/scopes.rb', line 47

def all
  @scopes
end

#exists?(scope) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/doorkeeper/oauth/scopes.rb', line 30

def exists?(scope)
  scope = scope.to_s

  @scopes.any? do |allowed_scope|
    if dynamic_scopes_enabled? && dynamic_scopes_present?(allowed_scope, scope)
      dynamic_scope_match?(allowed_scope, scope)
    else
      allowed_scope == scope
    end
  end
end

#scopes?(scopes) ⇒ Boolean Also known as: has_scopes?

Returns:

  • (Boolean)


55
56
57
# File 'lib/doorkeeper/oauth/scopes.rb', line 55

def scopes?(scopes)
  scopes.all? { |scope| exists?(scope) }
end

#to_sObject



51
52
53
# File 'lib/doorkeeper/oauth/scopes.rb', line 51

def to_s
  @scopes.join(" ")
end