Class: Mumukit::Auth::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/auth/role.rb

Defined Under Namespace

Classes: Admin, Editor, ExStudent, ForumSupervisor, Headmaster, Janitor, Moderator, Owner, Student, Teacher, Writer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol) ⇒ Role

Returns a new instance of Role.



16
17
18
# File 'lib/mumukit/auth/role.rb', line 16

def initialize(symbol)
  @symbol=symbol
end

Class Method Details

.parent(parent) ⇒ Object



50
51
52
# File 'lib/mumukit/auth/role.rb', line 50

def parent(parent)
  define_method(:parent) { self.class.parse(parent) }
end

.parse(role) ⇒ Object



54
55
56
57
# File 'lib/mumukit/auth/role.rb', line 54

def parse(role)
  @roles ||= {}
  @roles[role.to_sym] ||= "Mumukit::Auth::Role::#{role.to_s.camelize}".constantize.new(role.to_sym)
end

Instance Method Details

#_narrower_than_other?(other) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mumukit/auth/role.rb', line 45

def _narrower_than_other?(other)
  self.parent.class == other.class || self.parent._narrower_than_other?(other)
end

#allows?(resource_slug, permissions) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/mumukit/auth/role.rb', line 20

def allows?(resource_slug, permissions)
  permissions.role_allows?(to_sym, resource_slug) ||
      parent_allows?(resource_slug, permissions)
end

#broader_than?(other) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mumukit/auth/role.rb', line 33

def broader_than?(other)
  other.narrower_than? self
end

#narrower_than?(other) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mumukit/auth/role.rb', line 37

def narrower_than?(other)
  other.class != self.class && _narrower_than_other?(other)
end

#parent_allows?(resource_slug, permissions) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mumukit/auth/role.rb', line 25

def parent_allows?(resource_slug, permissions)
  parent.allows?(resource_slug, permissions)
end

#to_mumukit_roleObject



41
42
43
# File 'lib/mumukit/auth/role.rb', line 41

def to_mumukit_role
  self
end

#to_symObject



29
30
31
# File 'lib/mumukit/auth/role.rb', line 29

def to_sym
  @symbol
end