Skip to content

Commit

Permalink
Constructor accepts logger: parameter (#20)
Browse files Browse the repository at this point in the history
* Constructor accepts logger: parameter

* fix linter
  • Loading branch information
andreibondarev authored Oct 1, 2024
1 parent 9adb700 commit b4191d7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/milvus/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@

module Milvus
class Client
attr_reader :url, :api_key
attr_reader :url, :api_key, :adapter, :raise_error, :logger

API_VERSION = "v2/vectordb"

def initialize(url:, api_key: nil)
def initialize(
url:,
api_key: nil,
adapter: Faraday.default_adapter,
raise_error: false,
logger: nil
)
@url = url
@api_key = api_key
@adapter = adapter
@raise_error = raise_error
@logger = logger || Logger.new($stdout)
end

def collections
Expand Down Expand Up @@ -47,8 +56,10 @@ def connection
faraday.request :authorization, :Bearer, api_key
end
faraday.request :json
faraday.response :logger, logger, {headers: true, bodies: true, errors: true}
faraday.response :raise_error if raise_error
faraday.response :json, content_type: /\bjson$/
faraday.adapter Faraday.default_adapter
faraday.adapter adapter
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions spec/milvus/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Milvus::Client do
let(:client) {
described_class.new(
url: "localhost:8080",
api_key: "123"
)
}

describe "#initialize" do
it "creates a client" do
expect(client).to be_a(Milvus::Client)
end

it "accepts a custom logger" do
logger = Logger.new($stdout)
client = Milvus::Client.new(
url: "localhost:8080",
api_key: "123",
logger: logger
)
expect(client.logger).to eq(logger)
end
end
end

0 comments on commit b4191d7

Please sign in to comment.