Class: Rollenspiel::RoleProvider::RoleStructure

Inherits:
Object
  • Object
show all
Defined in:
app/models/rollenspiel/role_provider/role_structure.rb

Instance Method Summary collapse

Constructor Details

#initializeRoleStructure

Returns a new instance of RoleStructure.



4
5
6
7
8
# File 'app/models/rollenspiel/role_provider/role_structure.rb', line 4

def initialize
  @roles = []
  @inheritances = {}
  @callbacks = {on_grant: {}}
end

Instance Method Details

#layoutObject



31
32
33
34
35
36
37
# File 'app/models/rollenspiel/role_provider/role_structure.rb', line 31

def layout
  {
    inheritances: @inheritances,
    roles: @roles,
    callbacks: @callbacks
  }
end

#roles(*roles_with_options) ⇒ Object Also known as: role



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/rollenspiel/role_provider/role_structure.rb', line 10

def roles *roles_with_options
  roles = roles_with_options.dup
  options = roles.last.kind_of?(Hash) ? roles.pop : {}
  @roles << roles
  @roles << options[:inherits] if options[:inherits]
  @roles.flatten!
  @roles.compact!
  @roles.uniq!
  if inherits = options[:inherits]
    roles.each do |role|
      @inheritances[role] = inherits
    end
  end
  if on_grant = options[:on_grant]
    roles.each do |role|
      @callbacks[:on_grant][role] = RoleCallback.new(on_grant)
    end
  end
end