Sha256: 935db26ae6c43562e3bd53f3a66025f8cc1b52063a792a057416118ad79c6256

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module MeiliSearch
  module Rails
    module Configuration
      def configuration
        raise NotConfigured if @_config.blank?

        @_config
      end

      def configuration=(configuration)
        @_config = configuration
      end

      def deactivate!
        semaphore.synchronize do
          @_config.merge!(active: false)

          return unless block_given?

          yield

          @_config.merge!(active: true)
        end
      end

      def activate!
        semaphore.synchronize do
          @_config.merge!(active: true)
        end
      end

      def active?
        configuration.fetch(:active, true)
      end

      def black_hole
        @black_hole ||= NullObject.instance
      end

      def semaphore
        @semaphore ||= Mutex.new
      end

      def client
        return black_hole unless active?

        ::MeiliSearch::Client.new(
          configuration[:meilisearch_host] || 'http://localhost:7700',
          configuration[:meilisearch_api_key],
          configuration.slice(:timeout, :max_retries)
                       .merge(client_agents: MeiliSearch::Rails.qualified_version)
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
meilisearch-rails-0.7.3 lib/meilisearch/rails/configuration.rb