Skip to content

Commit 222bf66

Browse files
committed
Update dependencies, fix linting issues
1 parent b13d2dd commit 222bf66

22 files changed

Lines changed: 96 additions & 78 deletions

.rubocop.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require: rubocop-rspec
2+
13
AllCops:
24
NewCops: enable
35

@@ -37,3 +39,12 @@ Layout/LineLength:
3739
Lint/SuppressedException:
3840
Exclude:
3941
- examples/**
42+
43+
RSpec/ExampleLength:
44+
Enabled: false
45+
46+
RSpec/MultipleExpectations:
47+
Enabled: false
48+
49+
Style/HashSyntax:
50+
Enabled: false # We still want to support older versions of Ruby

Gemfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,21 @@ source 'https://rubygems.org'
44

55
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

7+
# Dev dependencies
8+
gem 'awesome_print', '~> 1.8'
9+
gem 'bundler', '~> 2.0'
10+
gem 'codecov', '~> 0.1'
11+
gem 'guard', '~> 2.16'
12+
gem 'guard-rubocop', '~> 1.3'
13+
gem 'rake', '~> 13.0'
14+
gem 'rspec', '~> 3.9'
15+
gem 'rspec_junit_formatter', '~> 0.4'
16+
gem 'rspec-legacy_formatters', '~> 1.0' # For codecov formatter
17+
gem 'rubocop', '~> 1.56'
18+
gem 'rubocop-rspec', '~> 2.24', require: false
19+
gem 'simplecov', '~> 0.18'
20+
gem 'timecop', '~> 0.9'
21+
gem 'webmock', '~> 3.8'
22+
723
# Specify your gem's dependencies in typesense.gemspec
824
gemspec

examples/aliases.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
##
44
# These examples walk you through operations specifically related to aliases
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Create a collection
99
create_response = @typesense.collections.create(
10-
"name": 'books_january',
11-
"fields": [
12-
{ "name": 'title', "type": 'string' },
13-
{ "name": 'authors', "type": 'string[]' },
14-
{ "name": 'authors_facet', "type": 'string[]', "facet": true },
15-
{ "name": 'publication_year', "type": 'int32' },
16-
{ "name": 'publication_year_facet', "type": 'string', "facet": true },
17-
{ "name": 'ratings_count', "type": 'int32' },
18-
{ "name": 'average_rating', "type": 'float' },
19-
{ "name": 'image_url', "type": 'string' }
10+
name: 'books_january',
11+
fields: [
12+
{ name: 'title', type: 'string' },
13+
{ name: 'authors', type: 'string[]' },
14+
{ name: 'authors_facet', type: 'string[]', facet: true },
15+
{ name: 'publication_year', type: 'int32' },
16+
{ name: 'publication_year_facet', type: 'string', facet: true },
17+
{ name: 'ratings_count', type: 'int32' },
18+
{ name: 'average_rating', type: 'float' },
19+
{ name: 'image_url', type: 'string' }
2020
],
21-
"default_sorting_field": 'ratings_count'
21+
default_sorting_field: 'ratings_count'
2222
)
2323

2424
ap create_response
2525

2626
# Create or update an existing alias
2727
create_alias_response = @typesense.aliases.upsert('books',
28-
"collection_name": 'books_january')
28+
collection_name: 'books_january')
2929
ap create_alias_response
3030

3131
# Add a book using the alias name `books`
3232
hunger_games_book = {
33-
'id': '1', 'original_publication_year': 2008, 'authors': ['Suzanne Collins'], 'average_rating': 4.34,
34-
'publication_year': 2008, 'publication_year_facet': '2008', 'authors_facet': ['Suzanne Collins'],
35-
'title': 'The Hunger Games',
36-
'image_url': 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
37-
'ratings_count': 4_780_653
33+
id: '1', original_publication_year: 2008, authors: ['Suzanne Collins'], average_rating: 4.34,
34+
publication_year: 2008, publication_year_facet: '2008', authors_facet: ['Suzanne Collins'],
35+
title: 'The Hunger Games',
36+
image_url: 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
37+
ratings_count: 4_780_653
3838
}
3939

4040
@typesense.collections['books'].documents.create(hunger_games_book)
4141

4242
# Search using the alias
4343
ap @typesense.collections['books'].documents.search(
44-
'q': 'hunger',
45-
'query_by': 'title',
46-
'sort_by': 'ratings_count:desc'
44+
q: 'hunger',
45+
query_by: 'title',
46+
sort_by: 'ratings_count:desc'
4747
)
4848

4949
# List all aliases

examples/collections_and_documents.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# These examples walk you through all the operations you can do on a collection and a document
55
# Search is specifically covered in another file in the examples folder
66

7-
require_relative './client_initialization'
7+
require_relative 'client_initialization'
88

99
##
1010
# Create a collection

examples/keys.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations to manage API Keys
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Let's setup some test data for this example
99
schema = {
@@ -95,18 +95,18 @@
9595
# This is useful when you store multi-tenant data in a single Typesense server, but you only want
9696
# a particular tenant to access their own data. You'd generate one scoped search key per tenant.
9797
# IMPORTANT: scoped search keys should only be generated *server-side*, so as to not leak the unscoped main search key to clients
98-
scoped_search_only_api_key = @typesense.keys.generate_scoped_search_key(unscoped_search_only_api_key, { 'filter_by': 'company_id:124' })
98+
scoped_search_only_api_key = @typesense.keys.generate_scoped_search_key(unscoped_search_only_api_key, { filter_by: 'company_id:124' })
9999
ap "scoped_search_only_api_key: #{scoped_search_only_api_key}"
100100

101101
# Now let's search the data using the scoped API Key for company_id:124
102102
# You can do searches with this scoped_search_only_api_key from the server-side or client-side
103103
scoped_typesense_client = Typesense::Client.new({
104-
'nodes': [{
105-
'host': 'localhost',
106-
'port': '8108',
107-
'protocol': 'http'
104+
nodes: [{
105+
host: 'localhost',
106+
port: '8108',
107+
protocol: 'http'
108108
}],
109-
'api_key': scoped_search_only_api_key
109+
api_key: scoped_search_only_api_key
110110
})
111111

112112
search_results = scoped_typesense_client.collections['users'].documents.search({
@@ -117,8 +117,8 @@
117117

118118
# Search for a user that exists, but is outside the current key's scope
119119
search_results = scoped_typesense_client.collections['users'].documents.search({
120-
'q': 'Maxwell',
121-
'query_by': 'user_name'
120+
q: 'Maxwell',
121+
query_by: 'user_name'
122122
})
123123
ap search_results # Will return empty result set
124124

examples/overrides.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations specifically related to result overrides / curation
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Delete the collection if it already exists
99
begin
@@ -69,19 +69,19 @@
6969

7070
@typesense.collections['companies'].overrides.upsert(
7171
'promote-doofenshmirtz',
72-
"rule": {
73-
"query": 'doofen',
74-
"match": 'exact'
72+
rule: {
73+
query: 'doofen',
74+
match: 'exact'
7575
},
76-
"includes": [{ 'id' => '126', 'position' => 1 }]
76+
includes: [{ 'id' => '126', 'position' => 1 }]
7777
)
7878
@typesense.collections['companies'].overrides.upsert(
7979
'promote-acme',
80-
"rule": {
81-
"query": 'stark',
82-
"match": 'exact'
80+
rule: {
81+
query: 'stark',
82+
match: 'exact'
8383
},
84-
"includes": [{ 'id' => '125', 'position' => 1 }]
84+
includes: [{ 'id' => '125', 'position' => 1 }]
8585
)
8686

8787
##

examples/search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations specifically related to search
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
##
99
# Create a collection

examples/synonyms.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations specifically related to synonyms
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Delete the collection if it already exists
99
begin

lib/typesense/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(options = {})
1111
@nearest_node = options[:nearest_node]
1212
@connection_timeout_seconds = options[:connection_timeout_seconds] || options[:timeout_seconds] || 10
1313
@healthcheck_interval_seconds = options[:healthcheck_interval_seconds] || 15
14-
@num_retries = options[:num_retries] || @nodes.length + (@nearest_node.nil? ? 0 : 1) || 3
14+
@num_retries = options[:num_retries] || (@nodes.length + (@nearest_node.nil? ? 0 : 1)) || 3
1515
@retry_interval_seconds = options[:retry_interval_seconds] || 0.1
1616
@api_key = options[:api_key]
1717

spec/typesense/aliases_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
it 'returns an alias object' do
4848
result = aliases['books']
4949

50-
expect(result).to be_a_kind_of(Typesense::Alias)
50+
expect(result).to be_a(Typesense::Alias)
5151
expect(result.instance_variable_get(:@name)).to eq('books')
5252
end
5353
end

0 commit comments

Comments
 (0)