Sha256: c3190712eeefb68af67d49b7108d925400476d6d64c403877b70259e9d32c040

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

# ActsAsIndexed
# Copyright (c) 2007 - 2010 Douglas F Shearer.
# http://douglasfshearer.com
# Distributed under the MIT license as included with this plugin.

module ActsAsIndexed
  # Used to set up and modify settings for acts_as_indexed.
  class Configuration

    # Sets the location for the index. Specify as an array. Heroku, for
    # example would use RAILS_ROOT/tmp/index, which would be set as
    # [Rails.root,'tmp','index]
    attr_accessor :index_file

    # Tuning value for the index partitioning. Larger values result in quicker
    # searches, but slower indexing. Default is 3.
    attr_reader :index_file_depth

    # Sets the minimum length for a word in a query. Words shorter than this
    # value are ignored in searches unless preceded by the '+' operator.
    # Default is 3.
    attr_reader :min_word_size

    # Proc that allows you to turn on or off index for a record.
    # Useful if you don't want the index to be updated if the target model is
    # should not return up in results, such as a draft post.
    attr_accessor :if_proc

    def initialize
      @index_file = Rails.root.join('index') if Rails.root
      @index_file_depth = 3
      @min_word_size = 3
      @if_proc = if_proc
    end

    def index_file=(file_path)
      # Under the old syntax this was an array of path parts.
      # If this is still using the array then rewrite to a Pathname.
      if file_path.is_a?(Pathname)
        @index_file = file_path
      else
        @index_file = Pathname.new(file_path.collect{|part| part.to_s}.join(File::SEPARATOR))
      end
    end

    def index_file_depth=(val)
      raise(ArgumentError, 'index_file_depth cannot be less than one (1)') if val < 1
      @index_file_depth = val
    end

    def min_word_size=(val)
      raise(ArgumentError, 'min_word_size cannot be less than one (1)') if val < 1
      @min_word_size = val
    end

    def if_proc
      @if_proc ||= Proc.new{true}
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_indexed-0.6.5 lib/acts_as_indexed/configuration.rb
acts_as_indexed-0.6.4 lib/acts_as_indexed/configuration.rb
acts_as_indexed-0.6.3 lib/acts_as_indexed/configuration.rb