Class: Mumukit::Auth::Scope
- Inherits:
-
Object
- Object
- Mumukit::Auth::Scope
- Defined in:
- lib/mumukit/auth/scope.rb
Instance Attribute Summary collapse
-
#grants ⇒ Object
Returns the value of attribute grants.
Class Method Summary collapse
Instance Method Summary collapse
- #add_grant!(*grants) ⇒ Object
- #allows?(resource_slug) ⇒ Boolean
- #as_json(_options = {}) ⇒ Object
-
#initialize(grants = []) ⇒ Scope
constructor
A new instance of Scope.
- #present? ⇒ Boolean
- #protect!(resource_slug) ⇒ Object
- #remove_grant!(grant) ⇒ Object
- #to_s ⇒ Object
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
#grants ⇒ Object
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
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(={}) to_s end |
#present? ⇒ 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::.new((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_s ⇒ Object
26 27 28 |
# File 'lib/mumukit/auth/scope.rb', line 26 def to_s grants.map(&:to_s).join(':') end |