Sha256: 176571ee122b36925f394de6b263ac0bfa5b393952bc05aa9fd2e093b1476937

Contents?: true

Size: 816 Bytes

Versions: 29

Compression:

Stored size: 816 Bytes

Contents

module UniverseCompiler
  module Universe

    module Index

      private

      attr_reader :by_name, :by_type, :by_uniq_key

      def setup_indices
        @by_name = {}
        @by_type = {}
        @by_uniq_key = {}
      end
      alias_method :clear_indices, :setup_indices


      def index(entity)
        # Non unique indices
        by_name[entity.name] ||= []
        by_type[entity.type] ||= []
        by_name[entity.name] << entity
        by_type[entity.type] << entity
        # Unique index
        ref = entity.respond_to?(:to_composite_key) ? entity.to_composite_key : [entity.type, entity.name]
        by_uniq_key[ref] = entity
      end

      def reindex_all(entities)
        clear_indices
        entities.each do |entity|
          index entity
        end
      end

    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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