Class: Garage::TokenScope::Config

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

Instance Method Summary collapse

Instance Method Details

#namespace(ns, &block) ⇒ Object



67
68
69
70
71
# File 'lib/garage/token_scope.rb', line 67

def namespace(ns, &block)
  @ns = ns
  instance_eval(&block)
  @ns = nil
end

#register(scope_symbol, options = {}, &block) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/garage/token_scope.rb', line 82

def register(scope_symbol, options={}, &block)
  if options[:namespace] || @ns
    scope_symbol = [options[:namespace] || @ns, scope_symbol].join(".").to_sym
  end
  scope = Scope.new(scope_symbol, options)
  scope.instance_eval(&block) if block_given?
  unless scope.hidden?
    scope.accessible_resources.each do |klass, action|
      required_scopes(klass, action) << scope.to_sym
    end
  end

  scopes[scope_symbol] = scope
end

#required_scopes(klass, action) ⇒ Object



77
78
79
80
# File 'lib/garage/token_scope.rb', line 77

def required_scopes(klass, action)
  @required_scopes ||= {}
  @required_scopes[[klass.to_s, action]] ||= []
end

#scopesObject



73
74
75
# File 'lib/garage/token_scope.rb', line 73

def scopes
  @scopes ||= {}
end