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
8
# File 'lib/mumukit/auth/scope.rb', line 5

def initialize(grants=[])
  @grants = []
  add_grant! *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



49
50
51
# File 'lib/mumukit/auth/scope.rb', line 49

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

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



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

def ==(other)
  self.class == other.class && self.grants == other.grants
end

#add_grant!(*grants) ⇒ Object



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

def add_grant!(*grants)
  grants.each { |grant| push_and_compact! grant }
end

#allows?(resource_slug) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#as_json(_options = {}) ⇒ Object



53
54
55
# File 'lib/mumukit/auth/scope.rb', line 53

def as_json(_options={})
  to_s
end

#hashObject



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

def hash
  grants.hash
end

#inspectObject



41
42
43
# File 'lib/mumukit/auth/scope.rb', line 41

def inspect
  "<Mumukit::Auth::Scope #{to_s}>"
end

#merge(other) ⇒ Object



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

def merge(other)
  self.class.new grants + other.grants
end

#present?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mumukit/auth/scope.rb', line 45

def present?
  to_s.present?
end

#remove_grant!(grant) ⇒ Object



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

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

#to_sObject



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

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