Sha256: 1afb3eefeb8b277d34a9cc00cd9bd87effaa962036eb424144166f8d0fb2c25c

Contents?: true

Size: 1.46 KB

Versions: 10

Compression:

Stored size: 1.46 KB

Contents

module UniverseCompiler
  module Universe

    module Entities

      def empty?
        entities.empty?
      end

      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

      def <<(entity)
        add entity
        self
      end

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

      def clear
        entities.clear
        clear_indices
      end

      private

      attr_reader :entities

    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
universe_compiler-0.3.3 lib/universe_compiler/universe/entities.rb
universe_compiler-0.3.2 lib/universe_compiler/universe/entities.rb
universe_compiler-0.3.1 lib/universe_compiler/universe/entities.rb
universe_compiler-0.3.0 lib/universe_compiler/universe/entities.rb
universe_compiler-0.2.16 lib/universe_compiler/universe/entities.rb
universe_compiler-0.2.15 lib/universe_compiler/universe/entities.rb
universe_compiler-0.2.14 lib/universe_compiler/universe/entities.rb
universe_compiler-0.2.13 lib/universe_compiler/universe/entities.rb
universe_compiler-0.2.12 lib/universe_compiler/universe/entities.rb
universe_compiler-0.2.11 lib/universe_compiler/universe/entities.rb