Class: Garage::TokenScope

Inherits:
Object
  • Object
show all
Defined in:
lib/garage/token_scope.rb

Defined Under Namespace

Classes: Ability, Config, Scope

Class Method Summary collapse

Class Method Details

.ability(user, scopes) ⇒ Object



28
29
30
31
32
# File 'lib/garage/token_scope.rb', line 28

def self.ability(user, scopes)
  scopes = scopes.map(&:to_sym)
  scopes = [:public] if scopes.empty? # backward compatiblity for scopes without any scope, assuming public
  Ability.new(user, configuration.scopes.slice(*scopes).values)
end

.all_scopesObject



12
13
14
# File 'lib/garage/token_scope.rb', line 12

def self.all_scopes
  configuration.scopes.values
end

.configurationObject



8
9
10
# File 'lib/garage/token_scope.rb', line 8

def self.configuration
  @config or raise "Garage::TokenScope.configure must be called in initializer"
end

.configure(&block) ⇒ Object



3
4
5
6
# File 'lib/garage/token_scope.rb', line 3

def self.configure(&block)
  @config = Config.new
  @config.instance_eval(&block)
end

.hidden_scopesObject



24
25
26
# File 'lib/garage/token_scope.rb', line 24

def self.hidden_scopes
  configuration.scopes.values.select(&:hidden?)
end

.optional_scopesObject



16
17
18
# File 'lib/garage/token_scope.rb', line 16

def self.optional_scopes
  configuration.scopes.values.select(&:optional?)
end

.revealed_scopesObject



20
21
22
# File 'lib/garage/token_scope.rb', line 20

def self.revealed_scopes
  configuration.scopes.values.reject(&:hidden?)
end