Class: Rollenspiel::RoleProvider::RoleBuilder
- Inherits:
-
Object
- Object
- Rollenspiel::RoleProvider::RoleBuilder
- Defined in:
- app/models/rollenspiel/role_provider/role_builder.rb
Defined Under Namespace
Classes: ClassRoleBuilder, InstanceRoleBuilder
Instance Method Summary collapse
- #build ⇒ Object
- #create ⇒ Object
-
#initialize(structure, role_builder) ⇒ RoleBuilder
constructor
A new instance of RoleBuilder.
Constructor Details
#initialize(structure, role_builder) ⇒ RoleBuilder
Returns a new instance of RoleBuilder.
32 33 34 35 |
# File 'app/models/rollenspiel/role_provider/role_builder.rb', line 32 def initialize structure, role_builder @structure = structure @role_builder = role_builder end |
Instance Method Details
#build ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/rollenspiel/role_provider/role_builder.rb', line 37 def build roles_by_key = {} @structure.layout[:roles].each do |role_or_name| if role_or_name.respond_to?(:id) roles_by_key[role_or_name] = role_or_name else roles_by_key[role_or_name] = @role_builder.build(role_or_name) end end @structure.layout[:inheritances].each do |role_or_name, inherits_roles| inherits_roles.each do |inherits_role_or_name| raise ArgumentError, "Role #{@role_builder} #{role_or_name} is not available" unless roles_by_key[role_or_name] if inherits_role_or_name.respond_to?(:id) roles_by_key[role_or_name].inherit inherits_role_or_name else roles_by_key[role_or_name].inherit roles_by_key[inherits_role_or_name] end end end @structure.layout[:callbacks][:on_grant].each do |role_or_name, role_callback| role = roles_by_key[role_or_name] role_callback.scope_to_role(role) end roles_by_key end |
#create ⇒ Object
63 64 65 |
# File 'app/models/rollenspiel/role_provider/role_builder.rb', line 63 def create build.each {|name, role| role.save! } end |