Class: Doorkeeper::OAuth::Scopes
- Inherits:
-
Object
- Object
- Doorkeeper::OAuth::Scopes
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/doorkeeper/oauth/scopes.rb
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<=>(other) ⇒ Object
- #add(*scopes) ⇒ Object
- #all ⇒ Object
- #exists?(scope) ⇒ Boolean
- #has_scopes?(scopes) ⇒ Boolean
-
#initialize ⇒ Scopes
constructor
A new instance of Scopes.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Scopes
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
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_sym) @scopes.uniq! end |
#all ⇒ Object
35 36 37 |
# File 'lib/doorkeeper/oauth/scopes.rb', line 35 def all @scopes end |
#exists?(scope) ⇒ Boolean
26 27 28 |
# File 'lib/doorkeeper/oauth/scopes.rb', line 26 def exists?(scope) @scopes.include? scope.to_sym end |
#has_scopes?(scopes) ⇒ Boolean
43 44 45 |
# File 'lib/doorkeeper/oauth/scopes.rb', line 43 def has_scopes?(scopes) scopes.all? { |s| exists?(s) } end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/doorkeeper/oauth/scopes.rb', line 39 def to_s @scopes.join(" ") end |