Sha256: 997702a3703b405d68bf7b4208df49657dd4eb0df3f202dbf67dcb4491d0c01f

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

module Lita
  module Handlers
    class Enhance < Handler
      # Instances of this class represent indexes of nodes based on identifying
      # facets of that node.  Nodes are added to the index where the key is the
      # term that we're indexing on, and the value is the node that matches
      # that term.
      #
      # Nodes can then be later found in the index.
      class NodeIndex
        attr_reader :redis, :index_name

        def initialize(redis, index_name)
          @redis = redis
          @index_name = index_name
        end

        # Adds a node to the index
        def []=(key, node)
          redis.hset(index_name, key, node.name)
        end

        # Finds a node in the index. A Node object is return if found, otherwise nil is returned.
        def [](key)
          node_name = redis.hget(index_name, key)
          Node.load(redis, node_name)
        end

        # Returns the number of keys that are stored in this index.
        def size
          redis.hlen(index_name)
        end

        # Returns all the keys that defined in this index.
        def keys
          redis.hkeys(index_name)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lita-enhance-0.9.3 lib/lita/handlers/enhance/node_index.rb
lita-enhance-0.9.2 lib/lita/handlers/enhance/node_index.rb
lita-enhance-0.9.1 lib/lita/handlers/enhance/node_index.rb
lita-enhance-0.9.0 lib/lita/handlers/enhance/node_index.rb