Class: DarDaDa::Role

Inherits:
Array
  • Object
show all
Defined in:
lib/dar_da_da/role.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Role

Returns a new instance of Role.



3
4
5
6
7
# File 'lib/dar_da_da/role.rb', line 3

def initialize(name)
  super()
  @name = name.to_sym
  @merge_rights_from = []
end

Instance Attribute Details

#merge_rights_fromObject (readonly)

Returns the value of attribute merge_rights_from.



9
10
11
# File 'lib/dar_da_da/role.rb', line 9

def merge_rights_from
  @merge_rights_from
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/dar_da_da/role.rb', line 9

def name
  @name
end

Instance Method Details

#<<(right) ⇒ Object



11
12
13
# File 'lib/dar_da_da/role.rb', line 11

def <<(right)
  super(right.to_sym)
end

#based_on(*roles) ⇒ Object



24
25
26
27
28
# File 'lib/dar_da_da/role.rb', line 24

def based_on(*roles)
  roles.each do |role|
    merge_rights_from << role.to_sym
  end
end

#finalizeObject



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

def finalize
  self.uniq!
end

#include?(right) ⇒ Boolean Also known as: member?

Returns:

  • (Boolean)


15
16
17
# File 'lib/dar_da_da/role.rb', line 15

def include?(right)
  super(right.to_sym)
end

#is_allowed_to(*names) ⇒ Object



20
21
22
# File 'lib/dar_da_da/role.rb', line 20

def is_allowed_to(*names)
  concat(names.map(&:to_sym))
end

#merge_rights(stack = [], &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/dar_da_da/role.rb', line 30

def merge_rights(stack=[], &block)
  raise "You defined a circular reference when configuring DarDaDa with 'based_on'." if stack.include?(name)
  stack << name
  merge_rights_from.uniq.each do |role_name|
    next if role_name == name
    from = yield(role_name)
    is_allowed_to(*from.merge_rights(stack, &block)) if from
  end
  self
end