Skip to content

Commit 9238ab2

Browse files
Fixes
1 parent 0746e40 commit 9238ab2

File tree

5 files changed

+28
-57
lines changed

5 files changed

+28
-57
lines changed

lib/weaviate/objects.rb

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ def list(
2323
req.params["sort"] = sort unless sort.nil?
2424
req.params["order"] = order unless order.nil?
2525
end
26-
27-
if response.success?
28-
response.body
29-
else
30-
response.body
31-
end
26+
27+
response.body
3228
end
3329

3430
# Create a new data object. The provided meta-data and schema values are validated.
@@ -42,9 +38,11 @@ def create(
4238
validate_consistency_level!(consistency_level) unless consistency_level.nil?
4339

4440
response = client.connection.post(PATH) do |req|
45-
req.params = {
46-
consistency_level: consistency_level.to_s.upcase
47-
} unless consistency_level.nil?
41+
unless consistency_level.nil?
42+
req.params = {
43+
consistency_level: consistency_level.to_s.upcase
44+
}
45+
end
4846

4947
req.body = {}
5048
req.body["class"] = class_name
@@ -53,11 +51,7 @@ def create(
5351
req.body["vector"] = vector unless vector.nil?
5452
end
5553

56-
if response.success?
57-
response.body
58-
else
59-
response.body
60-
end
54+
response.body
6155
end
6256

6357
# Batch create objects
@@ -72,11 +66,7 @@ def batch_create(
7266
req.body = {objects: objects}
7367
end
7468

75-
if response.success?
76-
response.body
77-
else
78-
response.body
79-
end
69+
response.body
8070
end
8171

8272
# Get a single data object.
@@ -93,11 +83,7 @@ def get(
9383
req.params["include"] = include unless include.nil?
9484
end
9585

96-
if response.success?
97-
response.body
98-
else
99-
response.body
100-
end
86+
response.body
10187
end
10288

10389
# Check if a data object exists
@@ -134,12 +120,8 @@ def update(
134120
req.body["properties"] = properties
135121
req.body["vector"] = vector unless vector.nil?
136122
end
137-
138-
if response.success?
139-
response.body
140-
else
141-
response.body
142-
end
123+
124+
response.body
143125
end
144126

145127
# Delete an individual data object from Weaviate.
@@ -169,7 +151,7 @@ def batch_delete(
169151
dry_run: nil
170152
)
171153
path = "batch/#{PATH}"
172-
154+
173155
unless consistency_level.nil?
174156
validate_consistency_level!(consistency_level)
175157

lib/weaviate/query.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get(
2828
limit: limit,
2929
offset: offset
3030
)
31-
response.original_hash.dig('data', 'Get', class_name)
31+
response.original_hash.dig("data", "Get", class_name)
3232
rescue Graphlient::Errors::ExecutionError => error
3333
raise Weaviate::Error.new(error.response.data.get.errors.messages.to_h)
3434
end
@@ -53,7 +53,7 @@ def aggs(
5353
group_by: group_by,
5454
object_limit: object_limit
5555
)
56-
response.original_hash.dig('data', 'Aggregate', class_name)
56+
response.original_hash.dig("data", "Aggregate", class_name)
5757
rescue Graphlient::Errors::ExecutionError => error
5858
raise Weaviate::Error.new(error.response.data.aggregate.errors.messages.to_h)
5959
end
@@ -80,7 +80,7 @@ def explore(
8080
limit: limit,
8181
offset: offset
8282
)
83-
response.original_hash.dig('data', 'Explore')
83+
response.original_hash.dig("data", "Explore")
8484
rescue Graphlient::Errors::ExecutionError => error
8585
raise Weaviate::Error.new(error.to_s)
8686
end

lib/weaviate/schema.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'pry'
4-
53
module Weaviate
64
class Schema < Base
75
PATH = "schema"
@@ -49,16 +47,14 @@ def create(
4947
end
5048

5149
if response.success?
52-
response.body
53-
else
54-
response.body
5550
end
51+
response.body
5652
end
5753

5854
# Remove a class (and all data in the instances) from the schema.
5955
def delete(class_name:)
6056
response = client.connection.delete("#{PATH}/#{class_name}")
61-
57+
6258
if response.success?
6359
response.body.empty?
6460
else
@@ -95,10 +91,8 @@ def update(
9591
end
9692

9793
if response.success?
98-
response.body
99-
else
100-
response.body
10194
end
95+
response.body
10296
end
10397

10498
# Add a property to an existing schema class.
@@ -111,10 +105,8 @@ def add_property(
111105
end
112106

113107
if response.success?
114-
response.body
115-
else
116-
response.body
117108
end
109+
response.body
118110
end
119111

120112
# Inspect the shards of a class

spec/weaviate/objects_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
category: "philosophy"
3434
}
3535
)
36-
expect(response.dig('class')).to eq('Question')
36+
expect(response.dig("class")).to eq("Question")
3737
end
3838
end
3939

@@ -53,7 +53,7 @@
5353
end
5454

5555
describe "#exists?" do
56-
let(:response) { OpenStruct.new(success?: true, status: 204, body: '') }
56+
let(:response) { OpenStruct.new(success?: true, status: 204, body: "") }
5757

5858
before do
5959
allow_any_instance_of(Faraday::Connection).to receive(:head)
@@ -84,7 +84,7 @@
8484
class_name: "Question",
8585
id: "123"
8686
)
87-
expect(response.dig('class')).to eq('Question')
87+
expect(response.dig("class")).to eq("Question")
8888
end
8989
end
9090

@@ -147,7 +147,7 @@
147147
answer: "42"
148148
}
149149
)
150-
expect(response.dig('class')).to eq('Question')
150+
expect(response.dig("class")).to eq("Question")
151151
end
152152
end
153153

spec/weaviate/schema_spec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
end
2727

2828
it "returns schemas" do
29-
expect(schema.list.dig('classes').count).to eq(1)
29+
expect(schema.list.dig("classes").count).to eq(1)
3030
end
3131
end
3232

@@ -41,7 +41,7 @@
4141

4242
it "returns the schema" do
4343
response = schema.get(class_name: "Question")
44-
expect(response.dig('class')).to eq('Question')
44+
expect(response.dig("class")).to eq("Question")
4545
end
4646
end
4747

@@ -74,7 +74,7 @@
7474
}
7575
]
7676
)
77-
expect(response.dig('class')).to eq('Question')
77+
expect(response.dig("class")).to eq("Question")
7878
end
7979
end
8080

@@ -108,16 +108,13 @@
108108
class_name: "Question",
109109
description: "Information from a Wheel of Fortune question"
110110
)
111-
expect(response.dig('class')).to eq('Question')
111+
expect(response.dig("class")).to eq("Question")
112112
end
113113
end
114114

115115
xdescribe "#add_property" do
116-
117-
118116
end
119117

120-
121118
describe "#shards" do
122119
let(:response) { OpenStruct.new(success?: true, body: shard_fixture) }
123120

0 commit comments

Comments
 (0)