Sha256: c17aceba1546ba9cddea2448011d10ca40053695096fdec411588857cb247a86

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 Bytes

Contents

module AlgoliaSearch
  module Configuration
    def initialize
      @client = nil
    end

    def configuration
      @@configuration || raise(NotConfigured, "Please configure AlgoliaSearch. Set AlgoliaSearch.configuration = {application_id: 'YOUR_APPLICATION_ID', api_key: 'YOUR_API_KEY'}")
    end

    def configuration=(configuration)
      @@configuration = configuration.merge(
        :user_agent => "Algolia for Rails (#{AlgoliaSearch::VERSION}); Rails (#{Rails::VERSION::STRING})",
        :symbolize_keys => false
      )
    end

    def client_opts
      @@opts ||= {}
    end

    def client_opts=(opts)
      @@opts = opts
    end

    def client
      if @client.nil?
        setup_client
      end

      @client
    end

    def setup_client
      @client = Algolia::Search::Client.new(Algolia::Search::Config.new(@@configuration), client_opts)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
algoliasearch-rails-2.3.0 lib/algoliasearch/configuration.rb
algoliasearch-rails-2.2.2 lib/algoliasearch/configuration.rb