module UniverseCompiler::Entity::TypeManagement::ClassMethods

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

Public Instance Methods

entity_type(value = nil) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

normalize_entity_type(entity_type_or_class) click to toggle source
# File lib/universe_compiler/entity/type_management.rb, line 32
def normalize_entity_type(entity_type_or_class)
  case entity_type_or_class
  when Class
    entity_type_or_class.entity_type
  when Symbol, String
    entity_type_or_class.to_sym
  end
end