Module: UniverseCompiler::Entity::TypeManagement::ClassMethods

Defined in:
lib/universe_compiler/entity/type_management.rb

Overview

** Methods to be added into the class the UniverseCompiler::Entity::TypeManagement is included in.

Instance Method Summary collapse

Instance Method Details

#entity_type(value = nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/universe_compiler/entity/type_management.rb', line 10

def entity_type(value = nil)
  if value.nil?
    @entity_type || name.underscore
  else
    self.entity_type = value
  end
end

#entity_type=(value) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/universe_compiler/entity/type_management.rb', line 18

def entity_type=(value)
  return if value == @entity_type
  raise UniverseCompiler::Error, "You cannot change an entity type for class '#{self.name}'" unless @entity_type.nil?
  raise UniverseCompiler::Error, 'Only Symbol is supported for entity_type !' unless value.is_a? Symbol
  mapping = UniverseCompiler::Entity::TypeManagement.types_classes_mapping
  if mapping.keys.include? value
    raise UniverseCompiler::Error, "Type '#{value}' already registered for another class (#{mapping[value]})" unless self == mapping[value]
  end
  mapping[value] = self
  @entity_type = value
end