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



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

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

Instance Method Details

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



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

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



57
58
59
# File 'lib/mumukit/auth/scope.rb', line 57

def as_json(_options={})
  to_s
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  grants.empty?
end

#has_broader_grant?(grant) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/mumukit/auth/scope.rb', line 65

def has_broader_grant?(grant)
  grants.any? { |it| it.allows? grant }
end

#hashObject



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

def hash
  grants.hash
end

#inspectObject



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

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

#merge(other) ⇒ Object



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

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

#present?Boolean

Returns:

  • (Boolean)


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

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

#remove_narrower_grants!(grant) ⇒ Object



61
62
63
# File 'lib/mumukit/auth/scope.rb', line 61

def remove_narrower_grants!(grant)
  grants.reject! { |it| grant.allows? it }
end

#to_sObject



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

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