Sha256: 8499eb1672d8cdcca6d1461521fac77827bc237b6b967dda8a4e0fe410622d01

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

require "rubygems"
require "bundler/setup"
Bundler.setup

require "active_support"
require "active_support/core_ext"
require "active_model"
require "elasticsearch"

if defined?(Rails)
  require "elasticity/railtie"
end

module Elasticity
  class Config
    attr_writer :logger, :client, :settings, :namespace, :pretty_json

    def logger
      return @logger if defined?(@logger)

      if defined?(Rails)
        @logger = Rails.logger
      else
        @logger = Logger.new(STDOUT)
      end
    end

    def client
      return @client if defined?(@client)
      @client = Elasticsearch::Client.new
    end

    def settings
      return @settings if defined?(@settings)
      @settings = {}
    end

    def namespace
      @namespace
    end

    def pretty_json
      @pretty_json || false
    end
  end

  def self.configure
    @config = Config.new
    yield(@config)
  end

  def self.config
    return @config if defined?(@config)
    @config = Config.new
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
es-elasticity-0.2.11 lib/elasticity_base.rb
es-elasticity-0.2.8 lib/elasticity_base.rb