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
- #empty? ⇒ Boolean
- #has_broader_grant?(grant) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(grants = []) ⇒ Scope
constructor
A new instance of Scope.
- #inspect ⇒ Object
- #merge(other) ⇒ Object
- #present? ⇒ Boolean
- #remove_grant!(grant) ⇒ Object
- #remove_narrower_grants!(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
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
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(={}) to_s end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/mumukit/auth/scope.rb', line 23 def empty? grants.empty? end |
#has_broader_grant?(grant) ⇒ Boolean
65 66 67 |
# File 'lib/mumukit/auth/scope.rb', line 65 def has_broader_grant?(grant) grants.any? { |it| it.allows? grant } end |
#hash ⇒ Object
37 38 39 |
# File 'lib/mumukit/auth/scope.rb', line 37 def hash grants.hash end |
#inspect ⇒ Object
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
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_s ⇒ Object
41 42 43 |
# File 'lib/mumukit/auth/scope.rb', line 41 def to_s grants.map(&:to_s).join(':') end |