Sha256: 57a5eb92b3ae71b6187db2397d93d6efd693aa5785de706e077029a2ba6c99da

Contents?: true

Size: 840 Bytes

Versions: 1

Compression:

Stored size: 840 Bytes

Contents

module Couchbase

  class Configuration

    DEFAULT_CONFIG = {
      host:     'localhost',
      bucket:   'default',
      password: ''
    }

    Bucket = Struct.new(:name, :password)

    attr_accessor :hosts, :buckets

    def initialize(config = {})
      config = DEFAULT_CONFIG.merge(symbolize_keys(config))
      @hosts = Array(config[:hosts] || config[:host] || config[:hostname])

      if config[:buckets]
        @buckets = config[:buckets].map do |b|
          b = symbolize_keys(b)
          Bucket.new(b[:name], b[:password])
        end
      else
        @buckets = [Bucket.new(config[:bucket], config[:password])]
      end
    end

    private

    def symbolize_keys(old_hash)
      {}.tap do |hash|
        old_hash.each_pair do |key, value|
          hash[key.to_sym] = value
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
couchbase-jruby-client-1.0.4-java lib/couchbase/configuration.rb