ilios 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18d160f81c3298017c1e7936a32b3c3668414ebc1c327c59ef24c4ad741aa16a
4
- data.tar.gz: d664a164d230db6deea79bdf8f80ad6e2225da9f31640a84868a4b6d4a91062f
3
+ metadata.gz: 035cde2f726822e26aa111fc8998c14f68849cd2ad5ac90c738d0b4fde8fa87c
4
+ data.tar.gz: e565f45883e0056d4b009790ca260dffbe3b42b2afc507d0cdd4bf30b765fab4
5
5
  SHA512:
6
- metadata.gz: 8d3634a3a2fab8cf35f514cde6fc741f37fb4aa876d8f96cf277d18e90606c5e52682b32731ffd0347bd7666a04df7496d486a0a7861fc189b622b175b2dce0a
7
- data.tar.gz: fd1e720c2b4dabe04b973a5db48d993188b630d6ec476bb22710062e11aed5e4fdb42245513b970f9b31508893be13dfa577d30527cb7748c5ccd1368a1c3b9f
6
+ metadata.gz: 577089ba568337c8482f137df676d50959aca02a17e02b0978bafd3dd8fb9063c344f466a19e8c17f8e950e390f8513249b8f1c1862ad42d4917cd4ffba17978
7
+ data.tar.gz: ecbf6f1f31990c9cc04a466ddd615725320157d91b1513417c3719830aad2b47909201626b1f73b504bfd1a2ef29fac8a012db060e327e3cef2cbaa870d82429
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --no-private
2
+ lib/**/*.rb
3
+ ext/**/*.c
4
+ *.md
5
+ LICENSE
data/README.md CHANGED
@@ -29,6 +29,8 @@ WITH REPLICATION = {
29
29
  };
30
30
  ```
31
31
 
32
+ Then, you can run the following code.
33
+
32
34
  ```ruby
33
35
  require 'ilios'
34
36
 
@@ -107,20 +109,29 @@ prepare_future = Ilios::Cassandra.session.prepare_async(<<~CQL)
107
109
  CQL
108
110
 
109
111
  prepare_future.on_success { |statement|
110
- statement.bind({
111
- id: 1,
112
- message: 'Hello World',
113
- created_at: Time.now,
114
- })
115
- result_future = Ilios::Cassandra.session.execute_async(statement)
116
- result_future.on_success { |result|
117
- p result
118
- p "success"
119
- }
120
- result_future.on_failure {
121
- p "fail"
122
- }
112
+ futures = []
113
+
114
+ 10.times do |i|
115
+ statement.bind({
116
+ id: i,
117
+ message: 'Hello World',
118
+ created_at: Time.now,
119
+ })
120
+ result_future = Ilios::Cassandra.session.execute_async(statement)
121
+ result_future.on_success { |result|
122
+ p result
123
+ p "success"
124
+ }
125
+ result_future.on_failure {
126
+ p "fail"
127
+ }
128
+
129
+ futures << result_future
130
+ end
131
+ futures.each(&:await)
123
132
  }
133
+
134
+ prepare_future.await
124
135
  ```
125
136
 
126
137
  ## Contributing
@@ -1,5 +1,12 @@
1
1
  #include "ilios.h"
2
2
 
3
+ /**
4
+ * Connects a session to the keyspace specified in +config+ method.
5
+ *
6
+ * @return [Cassandra::Session] A new session object.
7
+ * @raise [RuntimeError] If no host is specified to connect in +config+ method.
8
+ * @raise [Cassandra::ConnectError] If the connection fails for any reason.
9
+ */
3
10
  static VALUE cassandra_connect(VALUE self)
4
11
  {
5
12
  CassandraSession *cassandra_session;
data/ext/ilios/future.c CHANGED
@@ -34,6 +34,7 @@ static void future_thread_pool_init(future_thread_pool *pool)
34
34
  pool->queue = rb_funcall(cQueue, id_new, 0);
35
35
  for (int i = 0; i < THREAD_MAX; i++) {
36
36
  pool->thread[i] = rb_thread_create(future_result_yielder_thread, (void*)pool);
37
+ rb_funcall(pool->thread[i], id_abort_on_exception_set, 1, Qtrue);
37
38
  }
38
39
  }
39
40
 
@@ -112,11 +113,11 @@ static void future_result_failure_yield(CassandraFuture *cassandra_future)
112
113
  }
113
114
  }
114
115
 
115
- static VALUE future_result_yielder_synchronize(VALUE arg)
116
+ static VALUE future_result_yielder_synchronize(VALUE future)
116
117
  {
117
118
  CassandraFuture *cassandra_future;
118
119
 
119
- GET_FUTURE(arg, cassandra_future);
120
+ GET_FUTURE(future, cassandra_future);
120
121
 
121
122
  if (cass_future_error_code(cassandra_future->future) == CASS_OK) {
122
123
  future_result_success_yield(cassandra_future);
@@ -126,14 +127,29 @@ static VALUE future_result_yielder_synchronize(VALUE arg)
126
127
  return Qnil;
127
128
  }
128
129
 
129
- static VALUE future_result_yielder(VALUE arg)
130
+ static VALUE future_result_yielder_body(VALUE future)
130
131
  {
131
132
  CassandraFuture *cassandra_future;
132
133
 
133
- GET_FUTURE(arg, cassandra_future);
134
+ GET_FUTURE(future, cassandra_future);
134
135
 
135
136
  nogvl_future_wait(cassandra_future->future);
136
- return rb_mutex_synchronize(cassandra_future->proc_mutex, future_result_yielder_synchronize, arg);
137
+ return rb_mutex_synchronize(cassandra_future->proc_mutex, future_result_yielder_synchronize, future);
138
+
139
+ }
140
+
141
+ static VALUE future_result_yielder_ensure(VALUE future)
142
+ {
143
+ CassandraFuture *cassandra_future;
144
+
145
+ GET_FUTURE(future, cassandra_future);
146
+ uv_sem_post(&cassandra_future->sem);
147
+ return Qnil;
148
+ }
149
+
150
+ static VALUE future_result_yielder(VALUE future)
151
+ {
152
+ return rb_ensure(future_result_yielder_body, future, future_result_yielder_ensure, future);
137
153
  }
138
154
 
139
155
  static VALUE future_result_yielder_thread(void *arg)
@@ -147,6 +163,32 @@ static VALUE future_result_yielder_thread(void *arg)
147
163
  return Qnil;
148
164
  }
149
165
 
166
+ VALUE future_create(CassFuture *future, VALUE session, future_kind kind)
167
+ {
168
+ CassandraFuture *cassandra_future;
169
+ VALUE cassandra_future_obj;
170
+
171
+ cassandra_future_obj = CREATE_FUTURE(cassandra_future);
172
+ cassandra_future->kind = kind;
173
+ cassandra_future->future = future;
174
+ cassandra_future->session_obj = session;
175
+ cassandra_future->proc_mutex = rb_mutex_new();
176
+ uv_sem_init(&cassandra_future->sem, 0);
177
+ cassandra_future->already_waited = false;
178
+
179
+ return cassandra_future_obj;
180
+ }
181
+
182
+ /**
183
+ * Run block when future resolves to a value.
184
+ *
185
+ * @yieldparam value [Cassandra::Statement, Cassandra::Result] A value.
186
+ * Yields +Cassandra::Statement+ object when future was created by +Cassandra::Session#prepare_async+.
187
+ * Yields +Cassandra::Result+ object when future was created by +Cassandra::Session#execute_async+.
188
+ * @return [Cassandra::Future] self.
189
+ * @raise [Cassandra::ExecutionError] If this method will be called twice.
190
+ * @raise [ArgumentError] If no block was given.
191
+ */
150
192
  static VALUE future_on_success(VALUE self)
151
193
  {
152
194
  CassandraFuture *cassandra_future;
@@ -157,33 +199,34 @@ static VALUE future_on_success(VALUE self)
157
199
  if (cassandra_future->on_success_block) {
158
200
  rb_raise(eExecutionError, "It should not call twice");
159
201
  }
202
+ if (!rb_block_given_p()) {
203
+ rb_raise(rb_eArgError, "no block given");
204
+ }
160
205
 
161
- if (rb_block_given_p()) {
162
- rb_mutex_lock(cassandra_future->proc_mutex);
163
-
164
- if (!cassandra_future->on_failure_block) {
165
- // Invoke the callback with thread pool only once
166
- wakeup_thread = true;
167
- }
206
+ rb_mutex_lock(cassandra_future->proc_mutex);
168
207
 
169
- cassandra_future->on_success_block = rb_block_proc();
208
+ if (!cassandra_future->on_failure_block) {
209
+ // Invoke the callback with thread pool only once
210
+ wakeup_thread = true;
211
+ }
170
212
 
171
- if (cass_future_ready(cassandra_future->future)) {
172
- rb_mutex_unlock(cassandra_future->proc_mutex);
173
- if (cass_future_error_code(cassandra_future->future) == CASS_OK) {
174
- future_result_success_yield(cassandra_future);
175
- }
176
- return self;
177
- }
213
+ cassandra_future->on_success_block = rb_block_proc();
178
214
 
179
- if (wakeup_thread) {
180
- future_queue_push(future_thread_pool_get(cassandra_future), self);
181
- }
182
- rb_mutex_unlock(cassandra_future->proc_mutex);
215
+ if (wakeup_thread) {
216
+ future_queue_push(future_thread_pool_get(cassandra_future), self);
183
217
  }
218
+ rb_mutex_unlock(cassandra_future->proc_mutex);
219
+
184
220
  return self;
185
221
  }
186
222
 
223
+ /**
224
+ * Run block when future resolves to error.
225
+ *
226
+ * @return [Cassandra::Future] self.
227
+ * @raise [Cassandra::ExecutionError] If this method will be called twice.
228
+ * @raise [ArgumentError] If no block was given.
229
+ */
187
230
  static VALUE future_on_failure(VALUE self)
188
231
  {
189
232
  CassandraFuture *cassandra_future;
@@ -194,30 +237,48 @@ static VALUE future_on_failure(VALUE self)
194
237
  if (cassandra_future->on_failure_block) {
195
238
  rb_raise(eExecutionError, "It should not call twice");
196
239
  }
240
+ if (!rb_block_given_p()) {
241
+ rb_raise(rb_eArgError, "no block given");
242
+ }
197
243
 
198
- if (rb_block_given_p()) {
199
- rb_mutex_lock(cassandra_future->proc_mutex);
244
+ rb_mutex_lock(cassandra_future->proc_mutex);
200
245
 
201
- if (!cassandra_future->on_success_block) {
202
- // Invoke the callback with thread pool only once
203
- wakeup_thread = true;
204
- }
246
+ if (!cassandra_future->on_success_block) {
247
+ // Invoke the callback with thread pool only once
248
+ wakeup_thread = true;
249
+ }
205
250
 
206
- cassandra_future->on_failure_block = rb_block_proc();
251
+ cassandra_future->on_failure_block = rb_block_proc();
207
252
 
208
- if (cass_future_ready(cassandra_future->future)) {
209
- rb_mutex_unlock(cassandra_future->proc_mutex);
210
- if (cass_future_error_code(cassandra_future->future) != CASS_OK) {
211
- future_result_failure_yield(cassandra_future);
212
- }
213
- return self;
214
- }
253
+ if (wakeup_thread) {
254
+ future_queue_push(future_thread_pool_get(cassandra_future), self);
255
+ }
256
+ rb_mutex_unlock(cassandra_future->proc_mutex);
215
257
 
216
- if (wakeup_thread) {
217
- future_queue_push(future_thread_pool_get(cassandra_future), self);
218
- }
219
- rb_mutex_unlock(cassandra_future->proc_mutex);
258
+ return self;
259
+ }
260
+
261
+ /**
262
+ * Wait to complete a future's statement.
263
+ *
264
+ * @return [Cassandra::Future] self.
265
+ */
266
+ static VALUE future_await(VALUE self)
267
+ {
268
+ CassandraFuture *cassandra_future;
269
+
270
+ GET_FUTURE(self, cassandra_future);
271
+
272
+ if (cassandra_future->already_waited) {
273
+ rb_raise(eExecutionError, "It should not call twice");
274
+ }
275
+
276
+ if (cassandra_future->on_success_block || cassandra_future->on_failure_block) {
277
+ nogvl_sem_wait(&cassandra_future->sem);
278
+ } else {
279
+ nogvl_future_wait(cassandra_future->future);
220
280
  }
281
+ cassandra_future->already_waited = true;
221
282
  return self;
222
283
  }
223
284
 
@@ -238,6 +299,7 @@ static void future_destroy(void *ptr)
238
299
  if (cassandra_future->future) {
239
300
  cass_future_free(cassandra_future->future);
240
301
  }
302
+ uv_sem_destroy(&cassandra_future->sem);
241
303
  xfree(cassandra_future);
242
304
  }
243
305
 
@@ -263,6 +325,7 @@ void Init_future(void)
263
325
 
264
326
  rb_define_method(cFuture, "on_success", future_on_success, 0);
265
327
  rb_define_method(cFuture, "on_failure", future_on_failure, 0);
328
+ rb_define_method(cFuture, "await", future_await, 0);
266
329
 
267
330
  future_thread_pool_init(&thread_pool_prepare);
268
331
  future_thread_pool_init(&thread_pool_execute);
data/ext/ilios/ilios.h CHANGED
@@ -54,6 +54,9 @@ typedef struct
54
54
  VALUE on_success_block;
55
55
  VALUE on_failure_block;
56
56
  VALUE proc_mutex;
57
+
58
+ uv_sem_t sem;
59
+ bool already_waited;
57
60
  } CassandraFuture;
58
61
 
59
62
  extern const rb_data_type_t cassandra_session_data_type;
@@ -94,9 +97,11 @@ extern void Init_statement(void);
94
97
  extern void Init_result(void);
95
98
  extern void Init_future(void);
96
99
 
100
+ extern VALUE future_create(CassFuture *future, VALUE session, future_kind kind);
97
101
  extern void nogvl_future_wait(CassFuture *future);
98
102
  extern CassFuture *nogvl_session_prepare(CassSession* session, VALUE query);
99
103
  extern CassFuture *nogvl_session_execute(CassSession* session, CassStatement* statement);
104
+ extern void nogvl_sem_wait(uv_sem_t *sem);
100
105
 
101
106
  extern void statement_default_config(CassandraStatement *cassandra_statement);
102
107
  extern void result_await(CassandraResult *cassandra_result);
data/ext/ilios/nogvl.c CHANGED
@@ -51,3 +51,16 @@ CassFuture *nogvl_session_execute(CassSession* session, CassStatement* statement
51
51
  nogvl_session_execute_args args = { session, statement };
52
52
  return (CassFuture *)rb_thread_call_without_gvl(nogvl_session_execute_cb, &args, RUBY_UBF_PROCESS, 0);
53
53
  }
54
+
55
+ static void *nogvl_sem_wait_cb(void *ptr)
56
+ {
57
+ uv_sem_t *sem = (uv_sem_t *)ptr;
58
+ uv_sem_wait(sem);
59
+ return NULL;
60
+ }
61
+
62
+ void nogvl_sem_wait(uv_sem_t *sem)
63
+ {
64
+ // Releases GVL to run another thread while waiting
65
+ rb_thread_call_without_gvl(nogvl_sem_wait_cb, sem, RUBY_UBF_PROCESS, 0);
66
+ }
data/ext/ilios/result.c CHANGED
@@ -33,6 +33,12 @@ void result_await(CassandraResult *cassandra_result)
33
33
  }
34
34
  }
35
35
 
36
+ /**
37
+ * Loads next page synchronously
38
+ *
39
+ * @return [Cassandra::Result, nil] returns self or +nil+ if last page.
40
+ * @raise [Cassandra::ExecutionError] If the query is invalid or there is something wrong with the session.
41
+ */
36
42
  static VALUE result_next_page(VALUE self)
37
43
  {
38
44
  CassandraResult *cassandra_result;
@@ -176,23 +182,49 @@ static VALUE result_convert_row(const CassResult *result, const CassRow *row, si
176
182
  return hash;
177
183
  }
178
184
 
185
+ struct result_each_arg {
186
+ CassandraResult *cassandra_result;
187
+ CassIterator *iterator;
188
+ };
189
+
190
+ static VALUE result_each_body(VALUE a)
191
+ {
192
+ struct result_each_arg *args = (struct result_each_arg *)a;
193
+ size_t column_count = cass_result_column_count(args->cassandra_result->result);
194
+
195
+ while (cass_iterator_next(args->iterator)) {
196
+ const CassRow *row = cass_iterator_get_row(args->iterator);
197
+ rb_yield(result_convert_row(args->cassandra_result->result, row, column_count));
198
+ }
199
+ return Qnil;
200
+ }
201
+
202
+ static VALUE result_each_ensure(VALUE a)
203
+ {
204
+ CassIterator *iterator = (CassIterator *)a;
205
+ cass_iterator_free(iterator);
206
+ return Qnil;
207
+ }
208
+
209
+ /**
210
+ * Yield the row of result into a block.
211
+ *
212
+ * @return [Cassandra::Result, Enumerator] returns self or +Enumerator+ if block is not given.
213
+ */
179
214
  static VALUE result_each(VALUE self)
180
215
  {
181
216
  CassandraResult *cassandra_result;
182
217
  CassIterator *iterator;
183
- size_t column_count;
218
+ struct result_each_arg args;
184
219
 
185
220
  RETURN_ENUMERATOR(self, 0, 0);
186
221
 
187
222
  GET_RESULT(self, cassandra_result);
188
223
 
189
224
  iterator = cass_iterator_from_result(cassandra_result->result);
190
- column_count = cass_result_column_count(cassandra_result->result);
191
- while (cass_iterator_next(iterator)) {
192
- const CassRow *row = cass_iterator_get_row(iterator);
193
- rb_yield(result_convert_row(cassandra_result->result, row, column_count));
194
- }
195
- cass_iterator_free(iterator);
225
+ args.cassandra_result = cassandra_result;
226
+ args.iterator = iterator;
227
+ rb_ensure(result_each_body, (VALUE)&args, result_each_ensure, (VALUE)iterator);
196
228
 
197
229
  return self;
198
230
  }
data/ext/ilios/session.c CHANGED
@@ -15,26 +15,32 @@ const rb_data_type_t cassandra_session_data_type = {
15
15
  RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
16
16
  };
17
17
 
18
+ /**
19
+ * Prepares a given query asynchronously and returns a future prepared statement.
20
+ *
21
+ * @param query [String] A query to prepare.
22
+ * @return [Cassandra::Future] A future prepared statement.
23
+ * @raise [TypeError] If the query is not a string.
24
+ */
18
25
  static VALUE session_prepare_async(VALUE self, VALUE query)
19
26
  {
20
27
  CassandraSession *cassandra_session;
21
- CassandraFuture *cassandra_future;
22
28
  CassFuture *prepare_future;
23
- VALUE cassandra_future_obj;
24
29
 
25
30
  GET_SESSION(self, cassandra_session);
26
31
 
27
32
  prepare_future = nogvl_session_prepare(cassandra_session->session, query);
28
-
29
- cassandra_future_obj = CREATE_FUTURE(cassandra_future);
30
- cassandra_future->kind = prepare_async;
31
- cassandra_future->future = prepare_future;
32
- cassandra_future->session_obj = self;
33
- cassandra_future->proc_mutex = rb_mutex_new();
34
-
35
- return cassandra_future_obj;
33
+ return future_create(prepare_future, self, prepare_async);
36
34
  }
37
35
 
36
+ /**
37
+ * Prepares a given query.
38
+ *
39
+ * @param query [String] A query to prepare.
40
+ * @return [Cassandra::Statement] A statement to execute.
41
+ * @raise [Cassandra::ExecutionError] If the query is invalid or there is something wrong with the session.
42
+ * @raise [TypeError] If the query is not a string.
43
+ */
38
44
  static VALUE session_prepare(VALUE self, VALUE query)
39
45
  {
40
46
  CassandraSession *cassandra_session;
@@ -66,29 +72,34 @@ static VALUE session_prepare(VALUE self, VALUE query)
66
72
  return cassandra_statement_obj;
67
73
  }
68
74
 
75
+ /**
76
+ * Executes a given statement asynchronously and returns a future result.
77
+ *
78
+ * @param statement [Cassandra::Statement] A statement to execute.
79
+ * @return [Cassandra::Future] A future for result.
80
+ * @raise [TypeError] If the invalid object is given.
81
+ */
69
82
  static VALUE session_execute_async(VALUE self, VALUE statement)
70
83
  {
71
84
  CassandraSession *cassandra_session;
72
85
  CassandraStatement *cassandra_statement;
73
- CassandraFuture *cassandra_future;
74
86
  CassFuture *result_future;
75
- VALUE cassandra_future_obj;
76
87
 
77
88
  GET_SESSION(self, cassandra_session);
78
89
  GET_STATEMENT(statement, cassandra_statement);
79
90
 
80
91
  result_future = nogvl_session_execute(cassandra_session->session, cassandra_statement->statement);
81
-
82
- cassandra_future_obj = CREATE_FUTURE(cassandra_future);
83
- cassandra_future->kind = execute_async;
84
- cassandra_future->future = result_future;
85
- cassandra_future->session_obj = self;
86
- cassandra_future->statement_obj = statement;
87
- cassandra_future->proc_mutex = rb_mutex_new();
88
-
89
- return cassandra_future_obj;
92
+ return future_create(result_future, self, execute_async);
90
93
  }
91
94
 
95
+ /**
96
+ * Executes a given statement.
97
+ *
98
+ * @param statement [Cassandra::Statement] A statement to execute.
99
+ * @return [Cassandra::Result] A result.
100
+ * @raise [Cassandra::ExecutionError] If there is something wrong with the session.
101
+ * @raise [TypeError] If the invalid object is given.
102
+ */
92
103
  static VALUE session_execute(VALUE self, VALUE statement)
93
104
  {
94
105
  CassandraSession *cassandra_session;
@@ -115,9 +126,6 @@ static void session_destroy(void *ptr)
115
126
  CassandraSession *cassandra_session = (CassandraSession *)ptr;
116
127
 
117
128
  if (cassandra_session->session) {
118
- CassFuture *close_future = cass_session_close(cassandra_session->session);
119
- nogvl_future_wait(close_future);
120
- cass_future_free(close_future);
121
129
  cass_session_free(cassandra_session->session);
122
130
  }
123
131
  if (cassandra_session->connect_future) {
@@ -150,6 +150,16 @@ result_check:
150
150
  return ST_CONTINUE;
151
151
  }
152
152
 
153
+ /**
154
+ * Binds a specified column value to a query.
155
+ * A hash object should be given with column name as key.
156
+ *
157
+ * @param hash [Hash] A hash object to bind.
158
+ * @return [Cassandra::Statement] self.
159
+ * @raise [RangeError] If an invalid range of values was given.
160
+ * @raise [TypeError] If an invalid type of values was given.
161
+ * @raise [Cassandra::StatementError] If an invalid column name was given.
162
+ */
153
163
  static VALUE statement_bind(VALUE self, VALUE hash)
154
164
  {
155
165
  CassandraStatement *cassandra_statement;
@@ -161,6 +171,12 @@ static VALUE statement_bind(VALUE self, VALUE hash)
161
171
  return self;
162
172
  }
163
173
 
174
+ /**
175
+ * Sets the statement's page size.
176
+ *
177
+ * @param page_size [Integer] A page size.
178
+ * @return [Cassandra::Statement] self.
179
+ */
164
180
  static VALUE statement_page_size(VALUE self, VALUE page_size)
165
181
  {
166
182
  CassandraStatement *cassandra_statement;
data/ilios.gemspec CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = 'Cassandra driver written by C language'
12
12
  spec.description = 'Cassandra driver written by C language'
13
13
  spec.homepage = 'https://github.com/Watson1978/ilios'
14
+ spec.license = 'MIT'
14
15
  spec.required_ruby_version = '>= 3.0.0'
15
16
 
16
17
  spec.requirements << 'cmake'
@@ -25,7 +26,7 @@ Gem::Specification.new do |spec|
25
26
  spec.files =
26
27
  Dir.chdir(__dir__) do
27
28
  `git ls-files -z`.split("\x0").reject do |f|
28
- (f == __FILE__) || f.match(%r{\A(?:(?:test)/|\.(?:git|editorconfig|rubocop.*))})
29
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|example)/|\.(?:git|editorconfig|rubocop.*))})
29
30
  end
30
31
  end
31
32
  spec.require_paths = ['lib']
data/lib/ilios/version.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ilios
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.1'
5
5
  public_constant :VERSION
6
6
 
7
- CASSANDRA_CPP_DRIVER_VERSION = '2.17.0'
7
+ CASSANDRA_CPP_DRIVER_VERSION = '2.17.1'
8
8
  public_constant :CASSANDRA_CPP_DRIVER_VERSION
9
9
 
10
- LIBUV_VERSION = '1.46.0'
10
+ LIBUV_VERSION = '1.47.0'
11
11
  public_constant :LIBUV_VERSION
12
12
  end
data/lib/ilios.rb CHANGED
@@ -5,6 +5,7 @@ require 'ilios/version'
5
5
 
6
6
  module Ilios
7
7
  module Cassandra
8
+ # The default options.
8
9
  @@config = {
9
10
  keyspace: 'ilios',
10
11
  hosts: ['127.0.0.1'],
@@ -14,10 +15,24 @@ module Ilios
14
15
  page_size: 10_000
15
16
  }
16
17
 
18
+ #
19
+ # Configures the option for connection or execution.
20
+ # The default value will be overridden by the specified option.
21
+ #
22
+ # @param config [Hash] A hash object contained the options.
23
+ #
17
24
  def self.config=(config)
18
25
  @@config = @@config.merge(config)
19
26
  end
20
27
 
28
+ #
29
+ # Connects a session to the keyspace specified in +config+ method.
30
+ # The session object will be memorized by each threads.
31
+ #
32
+ # @return [Cassandra::Session] The session object.
33
+ # @raise [RuntimeError] If no host is specified to connect in +config+ method.
34
+ # @raise [Cassandra::ConnectError] If the connection fails for any reason.
35
+ #
21
36
  def self.session
22
37
  Thread.current[:ilios_cassandra_session] ||= connect
23
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ilios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_portile2
@@ -32,6 +32,7 @@ extensions:
32
32
  - ext/ilios/extconf.rb
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - ".yardopts"
35
36
  - Dockerfile
36
37
  - Gemfile
37
38
  - README.md
@@ -51,7 +52,8 @@ files:
51
52
  - lib/ilios/version.rb
52
53
  - sig/ilios.rbs
53
54
  homepage: https://github.com/Watson1978/ilios
54
- licenses: []
55
+ licenses:
56
+ - MIT
55
57
  metadata:
56
58
  homepage_uri: https://github.com/Watson1978/ilios
57
59
  source_code_uri: https://github.com/Watson1978/ilios