Sha256: 0464bd647be2ec53cc8438d4870df1f899b7ca0873b3a571297b04be3b27ec98
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
module Doorkeeper module OAuth class Scopes include Enumerable include Comparable def self.from_string(string) string ||= '' new.tap do |scope| scope.add(*string.split) end end def self.from_array(array) new.tap do |scope| scope.add(*array) end end delegate :each, :empty?, to: :@scopes def initialize @scopes = [] end def exists?(scope) @scopes.include? scope.to_s end def add(*scopes) @scopes.push(*scopes.map(&:to_s)) @scopes.uniq! end def all @scopes end def to_s @scopes.join(' ') end def has_scopes?(scopes) scopes.all? { |scope| exists?(scope) } end def +(other) self.class.from_array(all + to_array(other)) end def <=>(other) if other.respond_to?(:map) map(&:to_s).sort <=> other.map(&:to_s).sort else super end end def &(other) self.class.from_array(all & to_array(other)) end private def to_array(other) case other when Scopes other.all else other.to_a end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
doorkeeper-5.0.0 | lib/doorkeeper/oauth/scopes.rb |
doorkeeper-5.0.0.rc2 | lib/doorkeeper/oauth/scopes.rb |
doorkeeper-5.0.0.rc1 | lib/doorkeeper/oauth/scopes.rb |