class Mumukit::Auth::Scope
Attributes
grants[RW]
Public Class Methods
new(grants=[])
click to toggle source
# File lib/mumukit/auth/scope.rb, line 5 def initialize(grants=[]) @grants = [] add_grant! *grants end
parse(string='')
click to toggle source
# File lib/mumukit/auth/scope.rb, line 49 def self.parse(string='') new(string.split(':').map(&:to_mumukit_grant)) end
Public Instance Methods
==(other)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 27 def ==(other) self.class == other.class && self.grants == other.grants end
Also aliased as: eql?
add_grant!(*grants)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 14 def add_grant!(*grants) grants.each { |grant| push_and_compact! grant } end
allows?(resource_slug)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 10 def allows?(resource_slug) any_grant? { |grant| grant.allows? resource_slug } end
as_json(_options={})
click to toggle source
# File lib/mumukit/auth/scope.rb, line 53 def as_json(_options={}) to_s end
hash()
click to toggle source
# File lib/mumukit/auth/scope.rb, line 33 def hash grants.hash end
inspect()
click to toggle source
# File lib/mumukit/auth/scope.rb, line 41 def inspect "<Mumukit::Auth::Scope #{to_s}>" end
merge(other)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 23 def merge(other) self.class.new grants + other.grants end
present?()
click to toggle source
# File lib/mumukit/auth/scope.rb, line 45 def present? to_s.present? end
remove_grant!(grant)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 18 def remove_grant!(grant) grant = grant.to_mumukit_grant self.grants.delete(grant) end
to_s()
click to toggle source
# File lib/mumukit/auth/scope.rb, line 37 def to_s grants.map(&:to_s).join(':') end
Private Instance Methods
any_grant?(&block)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 59 def any_grant?(&block) @grants.any?(&block) end
has_broader_grant?(grant)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 74 def has_broader_grant?(grant) grants.any? { |it| it.allows? grant } end
push_and_compact!(grant)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 63 def push_and_compact!(grant) grant = grant.to_mumukit_grant return if has_broader_grant? grant remove_narrower_grants! grant grants << grant end
remove_narrower_grants!(grant)
click to toggle source
# File lib/mumukit/auth/scope.rb, line 70 def remove_narrower_grants!(grant) grants.reject! { |it| grant.allows? it } end