Class: Mumukit::Auth::Permissions
- Inherits:
-
Object
- Object
- Mumukit::Auth::Permissions
- Defined in:
- lib/mumukit/auth/token.rb,
lib/mumukit/auth/permissions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](organization) ⇒ Object
- #access?(organization) ⇒ Boolean
- #allows?(slug) ⇒ Boolean
- #as_json ⇒ Object
-
#initialize(grants) ⇒ Permissions
constructor
A new instance of Permissions.
- #present? ⇒ Boolean
- #protect!(slug) ⇒ Object
- #to_mumukit_auth_permissions ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(grants) ⇒ Permissions
Returns a new instance of Permissions.
4 5 6 |
# File 'lib/mumukit/auth/permissions.rb', line 4 def initialize(grants) @grants = grants end |
Class Method Details
.dump(permission) ⇒ Object
36 37 38 |
# File 'lib/mumukit/auth/permissions.rb', line 36 def self.dump() .to_s end |
.load(pattern) ⇒ Object
40 41 42 |
# File 'lib/mumukit/auth/permissions.rb', line 40 def self.load(pattern) parse(pattern) end |
.parse(pattern) ⇒ Object
44 45 46 |
# File 'lib/mumukit/auth/permissions.rb', line 44 def self.parse(pattern) new(pattern.split(':').map { |grant_pattern| Grant.parse(grant_pattern) }) end |
Instance Method Details
#[](organization) ⇒ Object
20 21 22 |
# File 'lib/mumukit/auth/permissions.rb', line 20 def [](organization) any_grant? { |grant| grant[organization] } end |
#access?(organization) ⇒ Boolean
16 17 18 |
# File 'lib/mumukit/auth/permissions.rb', line 16 def access?(organization) any_grant? { |grant| grant.access? organization } end |
#allows?(slug) ⇒ Boolean
12 13 14 |
# File 'lib/mumukit/auth/permissions.rb', line 12 def allows?(slug) any_grant? { |grant| grant.allows? slug } end |
#as_json ⇒ Object
24 25 26 |
# File 'lib/mumukit/auth/permissions.rb', line 24 def as_json to_s end |
#present? ⇒ Boolean
32 33 34 |
# File 'lib/mumukit/auth/permissions.rb', line 32 def present? to_s.present? end |
#protect!(slug) ⇒ Object
8 9 10 |
# File 'lib/mumukit/auth/permissions.rb', line 8 def protect!(slug) raise Mumukit::Auth::.new((slug)) unless allows?(slug) end |
#to_mumukit_auth_permissions ⇒ Object
53 54 55 |
# File 'lib/mumukit/auth/token.rb', line 53 def self end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/mumukit/auth/permissions.rb', line 28 def to_s @grants.map(&:to_s).uniq.join(':') end |