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
- #==(other) ⇒ Object (also: #eql?)
- #add_grant!(*grants) ⇒ Object
- #allows?(resource_slug) ⇒ Boolean
- #as_json(_options = {}) ⇒ Object
- #hash ⇒ Object
-
#initialize(grants = []) ⇒ Scope
constructor
A new instance of Scope.
- #inspect ⇒ Object
- #merge(other) ⇒ Object
- #present? ⇒ Boolean
- #remove_grant!(grant) ⇒ Object
- #to_s ⇒ Object
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
#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
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
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(={}) to_s end |
#hash ⇒ Object
33 34 35 |
# File 'lib/mumukit/auth/scope.rb', line 33 def hash grants.hash end |
#inspect ⇒ Object
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
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_s ⇒ Object
37 38 39 |
# File 'lib/mumukit/auth/scope.rb', line 37 def to_s grants.map(&:to_s).join(':') end |