Class: Doorkeeper::OAuth::Scopes

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScopes

Returns a new instance of Scopes.


24
25
26
# File 'lib/doorkeeper/oauth/scopes.rb', line 24

def initialize
  @scopes = []
end

Class Method Details

.from_array(array) ⇒ Object


16
17
18
19
20
# File 'lib/doorkeeper/oauth/scopes.rb', line 16

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

.from_string(string) ⇒ Object


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

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

Instance Method Details

#&(other) ⇒ Object


63
64
65
# File 'lib/doorkeeper/oauth/scopes.rb', line 63

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

#+(other) ⇒ Object


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

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

#<=>(other) ⇒ Object


55
56
57
58
59
60
61
# File 'lib/doorkeeper/oauth/scopes.rb', line 55

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

#add(*scopes) ⇒ Object


32
33
34
35
# File 'lib/doorkeeper/oauth/scopes.rb', line 32

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

#allObject


37
38
39
# File 'lib/doorkeeper/oauth/scopes.rb', line 37

def all
  @scopes
end

#exists?(scope) ⇒ Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/doorkeeper/oauth/scopes.rb', line 28

def exists?(scope)
  @scopes.include? scope.to_s
end

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

Returns:

  • (Boolean)

45
46
47
# File 'lib/doorkeeper/oauth/scopes.rb', line 45

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

#to_sObject


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

def to_s
  @scopes.join(" ")
end