Sha256: f1a3e6261c9072da31889083eb84876c34202a01c7fe2da49cd7048eb998239b

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

module Internals

  module Indexed

    #
    #
    class Index

      attr_reader :name, :result_identifier, :combinator, :categories

      delegate :load_from_cache,
               :analyze,
               :to => :categories

      def initialize name, options = {}
        @name                     = name

        @result_identifier        = options[:result_identifier] || name
        @bundle_class             = options[:indexed_bundle_class] # TODO This should actually be a fixed parameter.
        ignore_unassigned_tokens  = options[:ignore_unassigned_tokens] || false # TODO Move to query, somehow.

        @categories = Categories.new ignore_unassigned_tokens: ignore_unassigned_tokens
      end

      def define_category category_name, options = {}
        options = default_category_options.merge options

        new_category = Category.new category_name, self, options
        categories << new_category
        new_category
      end

      # By default, the category uses
      # * the index's bundle type.
      #
      def default_category_options
        {
          :indexed_bundle_class => @bundle_class
        }
      end

      # Return the possible combinations for this token.
      #
      # A combination is a tuple <token, index_bundle>.
      #
      def possible_combinations token
        categories.possible_combinations_for token
      end

      def to_s
        <<-INDEX
Indexed(#{name}):
  Result identifier: "#{result_identifier}"
  Categories:
  #{categories.indented_to_s}
INDEX
      end

    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
picky-2.5.2 lib/picky/internals/indexed/index.rb
picky-2.5.1 lib/picky/internals/indexed/index.rb
picky-2.5.0 lib/picky/internals/indexed/index.rb
picky-2.4.3 lib/picky/internals/indexed/index.rb
picky-2.4.2 lib/picky/internals/indexed/index.rb
picky-2.4.1 lib/picky/internals/indexed/index.rb
picky-2.4.0 lib/picky/internals/indexed/index.rb
picky-2.3.0 lib/picky/internals/indexed/index.rb
picky-2.2.1 lib/picky/internals/indexed/index.rb