Skip to content

Commit eecb4e3

Browse files
committed
refactor: Format code with RuboCop
1 parent 5772028 commit eecb4e3

19 files changed

+205
-172
lines changed

.rubocop.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ AllCops:
55

66
NewCops: enable
77

8-
TargetRubyVersion: 3.4
8+
TargetRubyVersion: 3.1
99

1010
AutoCorrect: true
11+
12+
SuggestExtensions: false
1113

1214
Style:
1315
StringLiterals:
@@ -27,11 +29,10 @@ Layout:
2729
Max: 120
2830

2931
FirstParameterIndentation:
30-
恩abled: true
32+
Enabled: true
3133
EnforcedStyle: indented
3234

33-
Indentation:
34-
Width:
35+
Indentation:
3536
Width: 2
3637

3738
Metrics:

Gemfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
source "https://rubygems.org"
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
24

35
gemspec
46

57
group :test do
6-
gem "rspec", "3.12.0"
7-
gem "ruby_memcheck", "3.0.1" if Gem::Platform.local.os == "linux"
8-
gem "rake-compiler", "1.2.9"
9-
gem "rake-compiler-dock", "1.9.1"
8+
gem 'rake-compiler', '1.2.9'
9+
gem 'rake-compiler-dock', '1.9.1'
10+
gem 'rspec', '3.12.0'
11+
gem 'ruby_memcheck', '3.0.1' if Gem::Platform.local.os == 'linux'
1012
end
1113

1214
group :development do
13-
gem "rdoc", "6.12.0"
14-
gem "rubocop", "1.59.0", require: false
15+
gem 'rdoc', '6.12.0'
16+
gem 'rubocop', '1.74.0', require: false
1517
end

Rakefile

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

3-
require "bundler/gem_tasks"
4-
require "rspec/core/rake_task"
5-
require "rake/extensiontask"
6-
require "rubocop/rake_task"
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
5+
require 'rake/extensiontask'
6+
require 'rubocop/rake_task'
77

88
# require "bundler"
9-
CHDB_SPEC = Bundler.load_gemspec("chdb.gemspec")
9+
CHDB_SPEC = Bundler.load_gemspec('chdb.gemspec')
1010

1111
RSpec::Core::RakeTask.new(:spec)
1212

13-
Rake::ExtensionTask.new("chdb") do |ext|
14-
ext.lib_dir = "lib/chdb"
13+
Rake::ExtensionTask.new('chdb') do |ext|
14+
ext.lib_dir = 'lib/chdb'
1515
end
1616

1717
RuboCop::RakeTask.new

chdb.gemspec

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1+
# frozen_string_literal: true
2+
13
begin
2-
require_relative "lib/chdb/version"
4+
require_relative 'lib/chdb/version'
35
rescue LoadError
4-
puts "WARNING: could not load ChDB::VERSION"
6+
puts 'WARNING: could not load ChDB::VERSION'
57
end
68

79
Gem::Specification.new do |s|
8-
s.name = "chdb"
9-
s.version = defined?(ChDB::VERSION) ? ChDB::VERSION : "0.0.0"
10+
s.name = 'chdb'
11+
s.version = defined?(ChDB::VERSION) ? ChDB::VERSION : '0.0.0'
1012

11-
s.summary = "Ruby library to interface with the chDB database engine (https://clickhouse.com/docs/chdb)."
13+
s.summary = 'Ruby library to interface with the chDB database engine (https://clickhouse.com/docs/chdb).'
1214
s.description = <<~TEXT
1315
Ruby library to interface with the chDB database engine (https://clickhouse.com/docs/chdb). Precompiled
1416
binaries are available for common platforms for recent versions of Ruby.
1517
TEXT
1618

17-
s.authors = ["Xiaozhe Yu", "Auxten Wang"]
19+
s.authors = ['Xiaozhe Yu', 'Auxten Wang']
1820

19-
s.licenses = ["Apache-2.0"]
21+
s.licenses = ['Apache-2.0']
2022

21-
s.required_ruby_version = Gem::Requirement.new(">= 3.1")
23+
s.required_ruby_version = Gem::Requirement.new('>= 3.1')
2224

23-
s.homepage = "https://github.com/chdb-io/chdb-ruby"
25+
s.homepage = 'https://github.com/chdb-io/chdb-ruby'
2426
s.metadata = {
25-
"homepage_uri" => "https://github.com/chdb-io/chdb-ruby",
26-
"bug_tracker_uri" => "https://github.com/chdb-io/chdb-ruby/issues",
27-
"changelog_uri" => "https://github.com/chdb-io/chdb-ruby/blob/main/CHANGELOG.md",
28-
"source_code_uri" => "https://github.com/chdb-io/chdb-ruby",
27+
'homepage_uri' => 'https://github.com/chdb-io/chdb-ruby',
28+
'bug_tracker_uri' => 'https://github.com/chdb-io/chdb-ruby/issues',
29+
'changelog_uri' => 'https://github.com/chdb-io/chdb-ruby/blob/main/CHANGELOG.md',
30+
'source_code_uri' => 'https://github.com/chdb-io/chdb-ruby',
2931

3032
# https://guides.rubygems.org/mfa-requirement-opt-in/
31-
"rubygems_mfa_required" => "true"
33+
'rubygems_mfa_required' => 'true'
3234
}
3335

3436
s.files = [
35-
"CHANGELOG.md",
36-
"LICENSE",
37-
"README.md",
38-
"lib/chdb.rb",
39-
"lib/chdb/constants.rb",
40-
"lib/chdb/data_path.rb",
41-
"lib/chdb/database.rb",
42-
"lib/chdb/errors.rb",
43-
"lib/chdb/local_result.rb",
44-
"lib/chdb/parameter_binding.rb",
45-
"lib/chdb/result_handler.rb",
46-
"lib/chdb/result_set.rb",
47-
"lib/chdb/sql_processor.rb",
48-
"lib/chdb/statement.rb",
49-
"lib/chdb/version_info.rb",
50-
"lib/chdb/version.rb"
37+
'CHANGELOG.md',
38+
'LICENSE',
39+
'README.md',
40+
'lib/chdb.rb',
41+
'lib/chdb/constants.rb',
42+
'lib/chdb/data_path.rb',
43+
'lib/chdb/database.rb',
44+
'lib/chdb/errors.rb',
45+
'lib/chdb/local_result.rb',
46+
'lib/chdb/parameter_binding.rb',
47+
'lib/chdb/result_handler.rb',
48+
'lib/chdb/result_set.rb',
49+
'lib/chdb/sql_processor.rb',
50+
'lib/chdb/statement.rb',
51+
'lib/chdb/version_info.rb',
52+
'lib/chdb/version.rb'
5153
]
5254

53-
s.rdoc_options = ["--main", "README.md"]
55+
s.rdoc_options = ['--main', 'README.md']
5456

55-
s.extensions << "ext/chdb/extconf.rb"
57+
s.extensions << 'ext/chdb/extconf.rb'
5658
end

ext/chdb/chdb.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
VALUE cChDBError;
99
VALUE cLocalResult;
1010

11-
void init_chdb_constants() {
11+
void init_chdb_constants()
12+
{
1213
VALUE mChDB = rb_define_module("ChDB");
1314
VALUE mChDBConstants = rb_define_module_under(mChDB, "Constants");
1415
VALUE mmChDBOpen = rb_define_module_under(mChDBConstants, "Open");
@@ -18,15 +19,21 @@ void init_chdb_constants() {
1819
rb_define_const(mmChDBOpen, "CREATE", INT2FIX(CHDB_OPEN_CREATE));
1920
}
2021

21-
void init_exception() {
22+
void init_exception()
23+
{
2224
VALUE mChDB = rb_define_module("ChDB");
2325
if (rb_const_defined(mChDB, rb_intern("Exception")))
26+
{
2427
cChDBError = rb_const_get(mChDB, rb_intern("Exception"));
28+
}
2529
else
30+
{
2631
cChDBError = rb_define_class_under(mChDB, "Exception", rb_eStandardError);
32+
}
2733
}
2834

29-
void init_local_result() {
35+
void init_local_result()
36+
{
3037
VALUE mChDB = rb_define_module("ChDB");
3138
cLocalResult = rb_define_class_under(mChDB, "LocalResult", rb_cObject);
3239
rb_define_alloc_func(cLocalResult, local_result_alloc);
@@ -36,7 +43,8 @@ void init_local_result() {
3643
rb_define_method(cLocalResult, "bytes_read", local_result_bytes_read, 0);
3744
}
3845

39-
void init_connection() {
46+
void init_connection()
47+
{
4048
VALUE mChDB = rb_define_module("ChDB");
4149
VALUE cConnection = rb_define_class_under(mChDB, "Connection", rb_cObject);
4250
rb_define_alloc_func(cConnection, connection_alloc);
@@ -49,11 +57,11 @@ void init_connection() {
4957
void Init_chdb(void)
5058
{
5159
DEBUG_PRINT("Initializing chdb extension");
52-
60+
5361
init_chdb_constants();
54-
init_exception();
62+
init_exception();
5563
init_local_result();
56-
init_connection();
64+
init_connection();
5765

5866
DEBUG_PRINT("chdb extension initialized successfully");
5967
}

ext/chdb/chdb.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ extern "C" {
1717
#define CHDB_EXPORT __attribute__((visibility("default")))
1818
struct local_result
1919
{
20-
char * buf;
20+
char *buf;
2121
size_t len;
22-
void * _vec; // std::vector<char> *, for freeing
22+
void *_vec; // std::vector<char> *, for freeing
2323
double elapsed;
2424
uint64_t rows_read;
2525
uint64_t bytes_read;
@@ -28,31 +28,31 @@ struct local_result
2828
#ifdef __cplusplus
2929
struct local_result_v2
3030
{
31-
char * buf = nullptr;
31+
char *buf = nullptr;
3232
size_t len = 0;
33-
void * _vec = nullptr; // std::vector<char> *, for freeing
33+
void *_vec = nullptr; // std::vector<char> *, for freeing
3434
double elapsed = 0.0;
3535
uint64_t rows_read = 0;
3636
uint64_t bytes_read = 0;
37-
char * error_message = nullptr;
37+
char *error_message = nullptr;
3838
};
3939
#else
4040
struct local_result_v2
4141
{
42-
char * buf;
42+
char *buf;
4343
size_t len;
44-
void * _vec; // std::vector<char> *, for freeing
44+
void *_vec; // std::vector<char> *, for freeing
4545
double elapsed;
4646
uint64_t rows_read;
4747
uint64_t bytes_read;
48-
char * error_message;
48+
char *error_message;
4949
};
5050
#endif
5151

52-
CHDB_EXPORT struct local_result * query_stable(int argc, char ** argv);
52+
CHDB_EXPORT struct local_result *query_stable(int argc, char ** argv);
5353
CHDB_EXPORT void free_result(struct local_result * result);
5454

55-
CHDB_EXPORT struct local_result_v2 * query_stable_v2(int argc, char ** argv);
55+
CHDB_EXPORT struct local_result_v2 *query_stable_v2(int argc, char ** argv);
5656
CHDB_EXPORT void free_result_v2(struct local_result_v2 * result);
5757

5858
#ifdef __cplusplus
@@ -68,7 +68,7 @@ struct query_queue
6868
std::condition_variable query_cv; // For query submission
6969
std::condition_variable result_cv; // For query result retrieval
7070
query_request current_query;
71-
local_result_v2 * current_result = nullptr;
71+
local_result_v2 *current_result = nullptr;
7272
bool has_query = false;
7373
bool shutdown = false;
7474
bool cleanup_done = false;
@@ -81,42 +81,42 @@ struct query_queue
8181
*/
8282
struct chdb_conn
8383
{
84-
void * server; /* ClickHouse LocalServer instance */
84+
void *server; /* ClickHouse LocalServer instance */
8585
bool connected; /* Connection state flag */
86-
void * queue; /* Query processing queue */
86+
void *queue; /* Query processing queue */
8787
};
8888

8989
/**
9090
* Creates a new chDB connection.
9191
* Only one active connection is allowed per process.
9292
* Creating a new connection with different path requires closing existing connection.
93-
*
93+
*
9494
* @param argc Number of command-line arguments
9595
* @param argv Command-line arguments array (--path=<db_path> to specify database location)
9696
* @return Pointer to connection pointer, or NULL on failure
9797
* @note Default path is ":memory:" if not specified
9898
*/
99-
CHDB_EXPORT struct chdb_conn ** connect_chdb(int argc, char ** argv);
99+
CHDB_EXPORT struct chdb_conn **connect_chdb(int argc, char ** argv);
100100

101101
/**
102102
* Closes an existing chDB connection and cleans up resources.
103103
* Thread-safe function that handles connection shutdown and cleanup.
104-
*
104+
*
105105
* @param conn Pointer to connection pointer to close
106106
*/
107107
CHDB_EXPORT void close_conn(struct chdb_conn ** conn);
108108

109109
/**
110110
* Executes a query on the given connection.
111111
* Thread-safe function that handles query execution in a separate thread.
112-
*
112+
*
113113
* @param conn Connection to execute query on
114114
* @param query SQL query string to execute
115115
* @param format Output format string (e.g., "CSV", default format)
116116
* @return Query result structure containing output or error message
117117
* @note Returns error result if connection is invalid or closed
118118
*/
119-
CHDB_EXPORT struct local_result_v2 * query_conn(struct chdb_conn * conn, const char * query, const char * format);
119+
CHDB_EXPORT struct local_result_v2 *query_conn(struct chdb_conn * conn, const char * query, const char * format);
120120

121121
#ifdef __cplusplus
122122
}

0 commit comments

Comments
 (0)