class Doorkeeper::OAuth::Scopes

Public Class Methods

from_array(array) click to toggle source
# 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) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 7
def self.from_string(string)
  string ||= ''
  new.tap do |scope|
    scope.add(*string.split)
  end
end
new() click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 22
def initialize
  @scopes = []
end

Public Instance Methods

&(other) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 59
def &(other)
  self.class.from_array(all & to_array(other))
end
+(other) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 47
def +(other)
  self.class.from_array(all + to_array(other))
end
<=>(other) click to toggle source
Calls superclass method
# File lib/doorkeeper/oauth/scopes.rb, line 51
def <=>(other)
  if other.respond_to?(:map)
    map(&:to_s).sort <=> other.map(&:to_s).sort
  else
    super
  end
end
add(*scopes) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 30
def add(*scopes)
  @scopes.push(*scopes.map(&:to_s))
  @scopes.uniq!
end
all() click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 35
def all
  @scopes
end
exists?(scope) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 26
def exists?(scope)
  @scopes.include? scope.to_s
end
has_scopes?(scopes) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 43
def has_scopes?(scopes)
  scopes.all? { |s| exists?(s) }
end
to_s() click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 39
def to_s
  @scopes.join(' ')
end

Private Instance Methods

to_array(other) click to toggle source
# File lib/doorkeeper/oauth/scopes.rb, line 65
def to_array(other)
  case other
  when Scopes
    other.all
  else
    other.to_a
  end
end