Class: Mumukit::Auth::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/auth/scope.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grants = []) ⇒ Scope

Returns a new instance of Scope.



5
6
7
# File 'lib/mumukit/auth/scope.rb', line 5

def initialize(grants=[])
  @grants = grants
end

Instance Attribute Details

#grantsObject

Returns the value of attribute grants.



3
4
5
# File 'lib/mumukit/auth/scope.rb', line 3

def grants
  @grants
end

Class Method Details

.parse(string) ⇒ Object



34
35
36
# File 'lib/mumukit/auth/scope.rb', line 34

def self.parse(string)
  new(string.split(':').map(&:to_mumukit_grant))
end

Instance Method Details

#add_grant!(*grants) ⇒ Object



17
18
19
# File 'lib/mumukit/auth/scope.rb', line 17

def add_grant!(*grants)
  self.grants.push *grants.map(&:to_mumukit_grant)
end

#allows?(resource_slug) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/mumukit/auth/scope.rb', line 13

def allows?(resource_slug)
  any_grant? { |grant| grant.allows? resource_slug }
end

#as_json(_options = {}) ⇒ Object



38
39
40
# File 'lib/mumukit/auth/scope.rb', line 38

def as_json(_options={})
  to_s
end

#present?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mumukit/auth/scope.rb', line 30

def present?
  to_s.present?
end

#protect!(resource_slug) ⇒ Object



9
10
11
# File 'lib/mumukit/auth/scope.rb', line 9

def protect!(resource_slug)
  raise Mumukit::Auth::UnauthorizedAccessError.new(unauthorized_message(resource_slug)) unless allows?(resource_slug)
end

#remove_grant!(grant) ⇒ Object



21
22
23
24
# File 'lib/mumukit/auth/scope.rb', line 21

def remove_grant!(grant)
  grant = grant.to_mumukit_grant
  self.grants.delete(grant)
end

#to_sObject



26
27
28
# File 'lib/mumukit/auth/scope.rb', line 26

def to_s
  grants.map(&:to_s).join(':')
end