Module: UniverseCompiler::Universe::Entities

Included in:
Base
Defined in:
lib/universe_compiler/universe/entities.rb

Instance Method Summary collapse

Instance Method Details

#<<(entity) ⇒ Object



30
31
32
33
# File 'lib/universe_compiler/universe/entities.rb', line 30

def <<(entity)
  add entity
  self
end

#add(entity) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/universe_compiler/universe/entities.rb', line 10

def add(entity)
  raise UniverseCompiler::Error, 'An entity cannot be null !' if entity.nil?
  raise UniverseCompiler::Error, 'An entity must have a name !' unless entity.respond_to? :name
  raise UniverseCompiler::Error, 'An entity must have a name !' if entity.name.nil? or entity.name.empty?
  unless UniverseCompiler::Entity::TypeManagement.valid_for_type? entity
    entity.extend UniverseCompiler::Entity::TypeManagement
  end
  raise UniverseCompiler::Error, "An entity named '#{entity.name}' already exists with the type '#{entity.type}' !" if by_uniq_key.keys.include? [entity.type, entity.name]
  raise UniverseCompiler::Error, 'Invalid type specified' if entity.type.nil?
  raise UniverseCompiler::Error, 'Type cannot contain spaces' if entity.type =~ /\s/
  # Normally here the entity is valid
  # We add it to the universe and index it
  entities << entity
  if entity.respond_to? :'universe='
    entity.universe = self
  end
  index entity
  entity
end

#clearObject



40
41
42
43
# File 'lib/universe_compiler/universe/entities.rb', line 40

def clear
  entities.clear
  clear_indices
end

#delete(entity) ⇒ Object



35
36
37
38
# File 'lib/universe_compiler/universe/entities.rb', line 35

def delete(entity)
  entities.delete entity
  reindex_all entities
end

#empty?Boolean



6
7
8
# File 'lib/universe_compiler/universe/entities.rb', line 6

def empty?
  entities.empty?
end