Sha256: 67899fe62f22f72c3435f2cd37a1100e8723aec171782b201bdf91260e490721

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Riddle
  class Configuration
    class DistributedIndex < Riddle::Configuration::Section
      def self.settings
        [ 
          :type, :local, :agent, :agent_blackhole,
          :agent_connect_timeout, :agent_query_timeout
        ]
      end
      
      attr_accessor :name, :local_indexes, :remote_indexes, :agent_blackhole,
        :agent_connect_timeout, :agent_query_timeout
      
      def initialize(name)
        @name             = name
        @local_indexes    = []
        @remote_indexes   = []
        @agent_blackhole  = []
      end
      
      def type
        "distributed"
      end
      
      def local
        self.local_indexes
      end
      
      def agent
        agents = remote_indexes.collect { |index| index.remote }.uniq
        agents.collect { |agent|
          agent + ":" + remote_indexes.select { |index|
            index.remote == agent
          }.collect { |index| index.name }.join(",")
        }
      end
            
      def render
        raise ConfigurationError unless valid?
        
        (
          ["index #{name}", "{"] +
          settings_body +
          ["}", ""]
        ).join("\n")
      end
      
      def valid?
        @local_indexes.length > 0 || @remote_indexes.length > 0
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riddle-1.4.0 lib/riddle/configuration/distributed_index.rb