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.


22
23
24
# File 'lib/doorkeeper/oauth/scopes.rb', line 22

def initialize
  @scopes = []
end

Class Method Details

.from_array(array) ⇒ Object


14
15
16
17
18
# File 'lib/doorkeeper/oauth/scopes.rb', line 14

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

.from_string(string) ⇒ Object


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

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

Instance Method Details

#&(other) ⇒ Object


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

def &(other)
  other_array = other.present? ? other.all : []
  self.class.from_array(all & other_array)
end

#+(other) ⇒ Object


47
48
49
50
51
52
53
# File 'lib/doorkeeper/oauth/scopes.rb', line 47

def +(other)
  if other.is_a? Scopes
    self.class.from_array(self.all + other.all)
  else
    super(other)
  end
end

#<=>(other) ⇒ Object


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

def <=>(other)
  self.map(&:to_s).sort <=> other.map(&:to_s).sort
end

#add(*scopes) ⇒ Object


30
31
32
33
# File 'lib/doorkeeper/oauth/scopes.rb', line 30

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

#allObject


35
36
37
# File 'lib/doorkeeper/oauth/scopes.rb', line 35

def all
  @scopes
end

#exists?(scope) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#has_scopes?(scopes) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#to_sObject


39
40
41
# File 'lib/doorkeeper/oauth/scopes.rb', line 39

def to_s
  @scopes.join(' ')
end