mongory 2.0.0-aarch64-linux → 2.1.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +5 -0
- data/SUBMODULE_INTEGRATION.md +5 -18
- data/docs/clang_bridge.md +1 -5
- data/examples/benchmark.rb +0 -16
- data/ext/mongory_ext/extconf.rb +1 -1
- data/ext/mongory_ext/mongory_ext_internal.h +0 -1
- data/ext/mongory_ext/rb_mongory_matcher.c +0 -80
- data/ext/mongory_ext/rb_mongory_value.c +67 -0
- data/lib/core/2.6/mongory_ext.so +0 -0
- data/lib/core/2.7/mongory_ext.so +0 -0
- data/lib/core/3.0/mongory_ext.so +0 -0
- data/lib/core/3.1/mongory_ext.so +0 -0
- data/lib/core/3.2/mongory_ext.so +0 -0
- data/lib/core/3.3/mongory_ext.so +0 -0
- data/lib/core/3.4/mongory_ext.so +0 -0
- data/lib/core/4.0/mongory_ext.so +0 -0
- data/lib/mongory/converters/condition_converter.rb +1 -1
- data/lib/mongory/matcher.rb +0 -13
- data/lib/mongory/query_builder.rb +1 -3
- data/lib/mongory/utils/context.rb +10 -15
- data/lib/mongory/utils/tree_renderer.rb +0 -10
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +28 -6
- data/renovate.json +6 -0
- data/scripts/build_with_core.sh +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '07852b7b0a96cbadbdb8d0a45fc0f9c6c4fd004c888c867654d1165f74331da1'
|
|
4
|
+
data.tar.gz: 8a6cd23c0a2773fb3951f38a8cbcf0f9c75dee761089108052202bba896c5d8e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1bda3e752c0f34dabcef10e3c6f52c769ca177b1f70d47292a8de5c951d7aefabee293355bb072d4400393b55d14274c27c59d364511bcf45261109e94afba4b
|
|
7
|
+
data.tar.gz: 00d0e20eba52dbfb813a7b28a2f3c82f72ac13f0e0666149a84add5aaee3fe9c7ce4e5b9e294ab2284cf99110b4e827d9b68b46ccd3c2f6f0a54a3047cc837a4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.0] - 2026-11-23
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **`Mongory.compile` & `Mongory.query`**: Added `Mongory.compile(condition)` (alias `build_matcher`) and `Mongory.query(records)` (alias `build_query`) as primary entry points aligned across the Mongory ecosystem.
|
|
7
|
+
|
|
8
|
+
### Fixes
|
|
9
|
+
- **C Extension Load Verification & Source-Gem Fallback (`lib/mongory.rb`)**: Fall back to `require 'mongory_ext'` when precompiled `core/<abi>/mongory_ext` is absent (supporting source-gem installs), and verify that `Mongory::Matcher#match?` is defined before reopening `Mongory::Matcher` so stale or incompatible C extensions fail fast with a clear `LoadError`.
|
|
10
|
+
|
|
11
|
+
## [2.0.1] - 2026-11-22
|
|
12
|
+
|
|
13
|
+
Aligns with `mongory-core` `v0.3.0` and finishes v2.0.0 cleanup.
|
|
14
|
+
|
|
15
|
+
### Fixes
|
|
16
|
+
- **C Extension (`rb_mongory_value.c`)**: Zero-initialize `rb_mongory_table_t` and `rb_mongory_array_t` lazy wrappers with OOM `NULL` guards and implement `.each` vtable methods (`rb_hash_foreach` / `RARRAY`) so every `mongory-core` container traversal contract is satisfied.
|
|
17
|
+
|
|
18
|
+
### Cleanup
|
|
19
|
+
- Removed stateful `Matcher#enable_trace`, `#disable_trace`, `#print_trace`, and no-op `Matcher.trace_result_colorful=` (all tracing uses stateless, thread-safe `#trace` / `#trace_tree`).
|
|
20
|
+
- Removed remaining legacy Pure-Ruby dead code (`TreeRenderer.mark_skipped`, `Utils::Context#need_convert`, `QueryBuilder#fast`, and stale `cJSON` comments).
|
|
21
|
+
- Synced `ext/mongory_ext/mongory-core` submodule to `v0.3.0`.
|
|
22
|
+
|
|
3
23
|
## [2.0.0] - 2026-11-22
|
|
4
24
|
|
|
5
25
|
Unifies `mongory-rb` on the `mongory-core` C99 native extension as the sole matching engine, eliminating Pure-Ruby dual-engine maintenance.
|
data/README.md
CHANGED
|
@@ -59,6 +59,11 @@ matched = records.mongory
|
|
|
59
59
|
rule = JSON.parse('{"age": {"$gte": 18}, "$or": [{"name": {"$regex": "^J"}}, {"name": "Bob"}]}')
|
|
60
60
|
records.mongory.where(rule).pluck('name')
|
|
61
61
|
# => ["Jack", "Bob"]
|
|
62
|
+
|
|
63
|
+
# 3. Compile once as a reusable, thread-safe Matcher (ideal for constants)
|
|
64
|
+
ADULT_RULE = Mongory.compile(:age.gte => 18, :active => true)
|
|
65
|
+
ADULT_RULE.match?(records.first)
|
|
66
|
+
# => true
|
|
62
67
|
```
|
|
63
68
|
|
|
64
69
|
### Query Builder Methods
|
data/SUBMODULE_INTEGRATION.md
CHANGED
|
@@ -52,7 +52,7 @@ sudo yum groupinstall "Development Tools" || sudo dnf groupinstall "Development
|
|
|
52
52
|
sudo yum install ruby-devel || sudo dnf install ruby-devel
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
> Optional: CMake
|
|
55
|
+
> Optional: CMake is only needed if you want to run the core C tests/benchmarks inside the `mongory-core` submodule (e.g., via CMake/ctest).
|
|
56
56
|
|
|
57
57
|
### 3. Build the project
|
|
58
58
|
|
|
@@ -97,7 +97,6 @@ If you prefer to control the build manually:
|
|
|
97
97
|
git submodule update --init --recursive
|
|
98
98
|
|
|
99
99
|
# 2. (Optional) Only needed if you run core tests/benchmarks inside the submodule
|
|
100
|
-
# Note: This step requires cJSON; typical mongory-rb usage does not.
|
|
101
100
|
# cd ext/mongory_ext/mongory-core
|
|
102
101
|
# ./build.sh --test
|
|
103
102
|
# cd ../../..
|
|
@@ -196,26 +195,14 @@ matcher.explain
|
|
|
196
195
|
git submodule update --init --recursive
|
|
197
196
|
```
|
|
198
197
|
|
|
199
|
-
**2.
|
|
200
|
-
```bash
|
|
201
|
-
# macOS
|
|
202
|
-
brew install cjson
|
|
203
|
-
|
|
204
|
-
# Ubuntu/Debian
|
|
205
|
-
sudo apt install libcjson-dev
|
|
206
|
-
|
|
207
|
-
# Verify installation
|
|
208
|
-
pkg-config --exists libcjson && echo "Found" || echo "Not found"
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
**3. Build errors**
|
|
198
|
+
**2. Build errors**
|
|
212
199
|
```bash
|
|
213
200
|
# Clean and rebuild
|
|
214
201
|
./scripts/build_with_core.sh --clean
|
|
215
202
|
./scripts/build_with_core.sh --debug
|
|
216
203
|
```
|
|
217
204
|
|
|
218
|
-
**
|
|
205
|
+
**3. C extension fails to load**
|
|
219
206
|
- Check Ruby version compatibility (>= 2.6.0)
|
|
220
207
|
- Ensure all system deps are installed
|
|
221
208
|
- Inspect error messages and compiler warnings
|
|
@@ -281,8 +268,8 @@ jobs:
|
|
|
281
268
|
run: bundle exec rspec
|
|
282
269
|
|
|
283
270
|
# Only needed if you also run mongory-core C tests/benchmarks (optional):
|
|
284
|
-
# - name: Install CMake
|
|
285
|
-
# run: sudo apt install -y cmake
|
|
271
|
+
# - name: Install CMake (only if running core tests)
|
|
272
|
+
# run: sudo apt install -y cmake
|
|
286
273
|
# - name: Build mongory-core tests (optional)
|
|
287
274
|
# run: |
|
|
288
275
|
# cd ext/mongory_ext/mongory-core
|
data/docs/clang_bridge.md
CHANGED
|
@@ -49,12 +49,8 @@ records.select { |r| matcher.match?(r) }
|
|
|
49
49
|
|
|
50
50
|
```ruby
|
|
51
51
|
matcher = Mongory::Matcher.new(:$or => [{ :name.regex => /^J/ }, { :age.gt => 20 }])
|
|
52
|
-
matcher.enable_trace
|
|
53
|
-
records.each { |r| matcher.match?(r) }
|
|
54
|
-
matcher.print_trace # prints detailed trace
|
|
55
|
-
matcher.disable_trace
|
|
56
52
|
|
|
57
|
-
# Structured explain/trace trees on a single Matcher
|
|
53
|
+
# Structured explain/trace trees on a single Matcher (stateless & thread-safe)
|
|
58
54
|
plan = matcher.explain_tree # => Hash ({ name:, condition:, priority:, children:, ... })
|
|
59
55
|
tree = matcher.trace_tree(records.first) # => Hash ({ ..., record:, result: :pass | :fail | :skip })
|
|
60
56
|
|
data/examples/benchmark.rb
CHANGED
|
@@ -120,22 +120,6 @@ end
|
|
|
120
120
|
raise "count mismatch" if builder.count != count_of_complex_query
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
# Complex query (Mongory) test
|
|
124
|
-
puts "\nComplex query (Mongory) fast mode (#{size} records):"
|
|
125
|
-
gc_handler do
|
|
126
|
-
builder = records.mongory.or(
|
|
127
|
-
{ :age.gte => 18 },
|
|
128
|
-
{ status: 'active' }
|
|
129
|
-
).fast
|
|
130
|
-
5.times do
|
|
131
|
-
result = Benchmark.measure do
|
|
132
|
-
builder.to_a
|
|
133
|
-
end
|
|
134
|
-
puts result
|
|
135
|
-
end
|
|
136
|
-
raise "count mismatch" if builder.count != count_of_complex_query
|
|
137
|
-
end
|
|
138
|
-
|
|
139
123
|
puts "\nComplex query (Mongory) use Matcher (#{size} records):"
|
|
140
124
|
gc_handler do
|
|
141
125
|
matcher = Mongory::Matcher.new({
|
data/ext/mongory_ext/extconf.rb
CHANGED
|
@@ -17,7 +17,7 @@ unless Dir.exist?(core_dir)
|
|
|
17
17
|
exit 1
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
# mongory-
|
|
20
|
+
# mongory-core itself has zero third-party C library dependencies; extconf.rb compiles it directly
|
|
21
21
|
|
|
22
22
|
# Normalize compiler flags across GCC/Clang on CI (Ruby 2.6 on Ubuntu may inject clang-only warn flags)
|
|
23
23
|
def scrub_flags_from_config!(keys, patterns)
|
|
@@ -28,7 +28,6 @@ typedef struct rb_mongory_matcher_t {
|
|
|
28
28
|
mongory_value *condition;
|
|
29
29
|
mongory_memory_pool *pool;
|
|
30
30
|
rb_mongory_memory_pool_t *scratch_free_list;
|
|
31
|
-
mongory_memory_pool *trace_pool;
|
|
32
31
|
mongory_table *string_map;
|
|
33
32
|
mongory_table *symbol_map;
|
|
34
33
|
mongory_array *mark_list;
|
|
@@ -31,10 +31,6 @@ static void rb_mongory_matcher_release_pools(rb_mongory_matcher_t *wrapper) {
|
|
|
31
31
|
scratch->next_scratch = NULL;
|
|
32
32
|
scratch->base.free(&scratch->base);
|
|
33
33
|
}
|
|
34
|
-
if (wrapper->trace_pool) {
|
|
35
|
-
wrapper->trace_pool->free(wrapper->trace_pool);
|
|
36
|
-
wrapper->trace_pool = NULL;
|
|
37
|
-
}
|
|
38
34
|
wrapper->matcher = NULL;
|
|
39
35
|
wrapper->condition = NULL;
|
|
40
36
|
wrapper->string_map = NULL;
|
|
@@ -216,7 +212,6 @@ static VALUE rb_mongory_matcher_match_body(VALUE arg) {
|
|
|
216
212
|
rb_mongory_matcher_t *self_wrapper = call->wrapper;
|
|
217
213
|
mongory_matcher *matcher = self_wrapper->matcher;
|
|
218
214
|
mongory_memory_pool *scratch_pool = call->scratch_pool;
|
|
219
|
-
mongory_memory_pool *trace_pool = self_wrapper->trace_pool;
|
|
220
215
|
mongory_value *data_value = rb_to_mongory_value_shallow(scratch_pool, call->data);
|
|
221
216
|
|
|
222
217
|
if (rb_mongory_error_handling(scratch_pool, "Match failed")) {
|
|
@@ -224,13 +219,6 @@ static VALUE rb_mongory_matcher_match_body(VALUE arg) {
|
|
|
224
219
|
}
|
|
225
220
|
|
|
226
221
|
bool result = mongory_matcher_match(matcher, data_value);
|
|
227
|
-
|
|
228
|
-
if (trace_pool) {
|
|
229
|
-
mongory_matcher_print_trace(matcher);
|
|
230
|
-
trace_pool->reset(trace_pool);
|
|
231
|
-
mongory_matcher_enable_trace(matcher, trace_pool);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
222
|
return result ? Qtrue : Qfalse;
|
|
235
223
|
}
|
|
236
224
|
|
|
@@ -422,62 +410,6 @@ static VALUE rb_mongory_matcher_trace(VALUE self, VALUE data) {
|
|
|
422
410
|
return res == ID2SYM(rb_intern("pass")) ? Qtrue : Qfalse;
|
|
423
411
|
}
|
|
424
412
|
|
|
425
|
-
// Mongory::Matcher#enable_trace
|
|
426
|
-
static VALUE rb_mongory_matcher_enable_trace(VALUE self) {
|
|
427
|
-
rb_mongory_matcher_t *wrapper = get_initialized_matcher(self);
|
|
428
|
-
if (wrapper->trace_pool) {
|
|
429
|
-
wrapper->trace_pool->free(wrapper->trace_pool);
|
|
430
|
-
wrapper->trace_pool = NULL;
|
|
431
|
-
}
|
|
432
|
-
rb_mongory_memory_pool_t *trace_pool = rb_mongory_memory_pool_new();
|
|
433
|
-
trace_pool->owner = wrapper;
|
|
434
|
-
mongory_memory_pool *trace_pool_base = &trace_pool->base;
|
|
435
|
-
mongory_matcher_enable_trace(wrapper->matcher, trace_pool_base);
|
|
436
|
-
|
|
437
|
-
if (trace_pool_base->error) {
|
|
438
|
-
char err_msg[256];
|
|
439
|
-
snprintf(err_msg, sizeof(err_msg), "%s",
|
|
440
|
-
trace_pool_base->error->message ? trace_pool_base->error->message : "Unknown error");
|
|
441
|
-
trace_pool_base->free(trace_pool_base);
|
|
442
|
-
rb_raise(rb_mongory_e_type_error, "Enable trace failed: %s", err_msg);
|
|
443
|
-
}
|
|
444
|
-
wrapper->trace_pool = trace_pool_base;
|
|
445
|
-
|
|
446
|
-
return Qnil;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Mongory::Matcher#disable_trace
|
|
450
|
-
static VALUE rb_mongory_matcher_disable_trace(VALUE self) {
|
|
451
|
-
rb_mongory_matcher_t *wrapper = get_initialized_matcher(self);
|
|
452
|
-
mongory_memory_pool *trace_pool = wrapper->trace_pool;
|
|
453
|
-
mongory_matcher_disable_trace(wrapper->matcher);
|
|
454
|
-
if (trace_pool) {
|
|
455
|
-
wrapper->trace_pool = NULL;
|
|
456
|
-
if (trace_pool->error) {
|
|
457
|
-
char err_msg[256];
|
|
458
|
-
snprintf(err_msg, sizeof(err_msg), "%s",
|
|
459
|
-
trace_pool->error->message ? trace_pool->error->message : "Unknown error");
|
|
460
|
-
trace_pool->free(trace_pool);
|
|
461
|
-
rb_raise(rb_mongory_e_type_error, "Disable trace failed: %s", err_msg);
|
|
462
|
-
}
|
|
463
|
-
trace_pool->free(trace_pool);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return Qnil;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// Mongory::Matcher#print_trace
|
|
470
|
-
static VALUE rb_mongory_matcher_print_trace(VALUE self) {
|
|
471
|
-
rb_mongory_matcher_t *wrapper = get_initialized_matcher(self);
|
|
472
|
-
if (!wrapper->trace_pool) {
|
|
473
|
-
return Qnil;
|
|
474
|
-
}
|
|
475
|
-
mongory_matcher_print_trace(wrapper->matcher);
|
|
476
|
-
rb_mongory_error_handling(wrapper->trace_pool, "Print trace failed");
|
|
477
|
-
|
|
478
|
-
return Qnil;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
413
|
// Mongory::Matcher#condition
|
|
482
414
|
static VALUE rb_mongory_matcher_condition(VALUE self) {
|
|
483
415
|
rb_mongory_matcher_t *wrapper = get_initialized_matcher(self);
|
|
@@ -492,21 +424,12 @@ static VALUE rb_mongory_matcher_context(VALUE self) {
|
|
|
492
424
|
return wrapper->ctx ? wrapper->ctx : Qnil;
|
|
493
425
|
}
|
|
494
426
|
|
|
495
|
-
// Mongory::Matcher.trace_result_colorful=(colorful)
|
|
496
|
-
static VALUE rb_mongory_matcher_trace_result_colorful(VALUE self, VALUE colorful) {
|
|
497
|
-
(void)self;
|
|
498
|
-
mongory_matcher_trace_result_colorful_set(RTEST(colorful));
|
|
499
|
-
|
|
500
|
-
return Qnil;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
427
|
void rb_mongory_init_matcher(void) {
|
|
504
428
|
rb_mongory_c_matcher = rb_define_class_under(rb_mongory_m_mongory, "Matcher", rb_cObject);
|
|
505
429
|
rb_define_alloc_func(rb_mongory_c_matcher, rb_mongory_matcher_alloc);
|
|
506
430
|
|
|
507
431
|
rb_define_method(rb_mongory_c_matcher, "initialize", rb_mongory_matcher_initialize, -1);
|
|
508
432
|
rb_define_method(rb_mongory_c_matcher, "initialize_copy", rb_mongory_matcher_initialize_copy, 1);
|
|
509
|
-
rb_define_singleton_method(rb_mongory_c_matcher, "trace_result_colorful=", rb_mongory_matcher_trace_result_colorful, 1);
|
|
510
433
|
rb_define_method(rb_mongory_c_matcher, "match?", rb_mongory_matcher_match, 1);
|
|
511
434
|
rb_define_method(rb_mongory_c_matcher, "explain_tree", rb_mongory_matcher_explain_tree, 0);
|
|
512
435
|
rb_define_method(rb_mongory_c_matcher, "explain", rb_mongory_matcher_explain, 0);
|
|
@@ -514,7 +437,4 @@ void rb_mongory_init_matcher(void) {
|
|
|
514
437
|
rb_define_method(rb_mongory_c_matcher, "context", rb_mongory_matcher_context, 0);
|
|
515
438
|
rb_define_method(rb_mongory_c_matcher, "trace_tree", rb_mongory_matcher_trace_tree, 1);
|
|
516
439
|
rb_define_method(rb_mongory_c_matcher, "trace", rb_mongory_matcher_trace, 1);
|
|
517
|
-
rb_define_method(rb_mongory_c_matcher, "enable_trace", rb_mongory_matcher_enable_trace, 0);
|
|
518
|
-
rb_define_method(rb_mongory_c_matcher, "disable_trace", rb_mongory_matcher_disable_trace, 0);
|
|
519
|
-
rb_define_method(rb_mongory_c_matcher, "print_trace", rb_mongory_matcher_print_trace, 0);
|
|
520
440
|
}
|
|
@@ -181,15 +181,61 @@ static mongory_value *rb_mongory_table_get(mongory_table *self, char *key) {
|
|
|
181
181
|
return rb_to_mongory_value_shallow(table->base.pool, rb_value);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
typedef struct {
|
|
185
|
+
mongory_memory_pool *pool;
|
|
186
|
+
void *acc;
|
|
187
|
+
mongory_table_each_pair_callback_func callback;
|
|
188
|
+
bool completed;
|
|
189
|
+
} rb_table_each_ctx_t;
|
|
190
|
+
|
|
191
|
+
static int rb_mongory_table_each_cb(VALUE key, VALUE val, VALUE arg) {
|
|
192
|
+
rb_table_each_ctx_t *ctx = (rb_table_each_ctx_t *)arg;
|
|
193
|
+
const char *key_cstr;
|
|
194
|
+
if (RB_TYPE_P(key, T_SYMBOL)) {
|
|
195
|
+
key_cstr = rb_id2name(rb_sym2id(key));
|
|
196
|
+
} else if (RB_TYPE_P(key, T_STRING)) {
|
|
197
|
+
key_cstr = StringValueCStr(key);
|
|
198
|
+
} else {
|
|
199
|
+
VALUE key_str = rb_funcall(key, rb_intern("to_s"), 0);
|
|
200
|
+
key_cstr = StringValueCStr(key_str);
|
|
201
|
+
}
|
|
202
|
+
mongory_value *mg_val = rb_to_mongory_value_shallow(ctx->pool, val);
|
|
203
|
+
if (!ctx->callback((char *)key_cstr, mg_val, ctx->acc)) {
|
|
204
|
+
ctx->completed = false;
|
|
205
|
+
return ST_STOP;
|
|
206
|
+
}
|
|
207
|
+
return ST_CONTINUE;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static bool rb_mongory_table_each(mongory_table *self, void *acc, mongory_table_each_pair_callback_func callback) {
|
|
211
|
+
rb_mongory_table_t *table = (rb_mongory_table_t *)self;
|
|
212
|
+
rb_table_each_ctx_t ctx = {
|
|
213
|
+
.pool = self->pool,
|
|
214
|
+
.acc = acc,
|
|
215
|
+
.callback = callback,
|
|
216
|
+
.completed = true,
|
|
217
|
+
};
|
|
218
|
+
rb_hash_foreach(table->rb_hash, rb_mongory_table_each_cb, (VALUE)&ctx);
|
|
219
|
+
return ctx.completed;
|
|
220
|
+
}
|
|
221
|
+
|
|
184
222
|
mongory_value *rb_mongory_table_wrap(mongory_memory_pool *pool, VALUE rb_hash) {
|
|
185
223
|
rb_mongory_table_t *table = MG_ALLOC_PTR(pool, rb_mongory_table_t);
|
|
224
|
+
if (!table) {
|
|
225
|
+
return NULL;
|
|
226
|
+
}
|
|
227
|
+
memset(table, 0, sizeof(rb_mongory_table_t));
|
|
186
228
|
rb_mongory_memory_pool_t *rb_pool = (rb_mongory_memory_pool_t *)pool;
|
|
187
229
|
table->base.pool = pool;
|
|
188
230
|
table->base.get = rb_mongory_table_get;
|
|
231
|
+
table->base.each = rb_mongory_table_each;
|
|
189
232
|
table->rb_hash = rb_hash;
|
|
190
233
|
table->base.count = RHASH_SIZE(rb_hash);
|
|
191
234
|
table->owner = rb_pool->owner;
|
|
192
235
|
mongory_value *mg_value = mongory_value_wrap_t(pool, &table->base);
|
|
236
|
+
if (!mg_value) {
|
|
237
|
+
return NULL;
|
|
238
|
+
}
|
|
193
239
|
mg_value->origin = (void *)rb_hash;
|
|
194
240
|
mg_value->to_str = rb_mongory_value_to_cstr;
|
|
195
241
|
return mg_value;
|
|
@@ -205,15 +251,36 @@ static mongory_value *rb_mongory_array_get(mongory_array *self, size_t index) {
|
|
|
205
251
|
return rb_to_mongory_value_shallow(self->pool, rb_value);
|
|
206
252
|
}
|
|
207
253
|
|
|
254
|
+
static bool rb_mongory_array_each(mongory_array *self, void *acc, mongory_array_callback_func callback) {
|
|
255
|
+
rb_mongory_array_t *array = (rb_mongory_array_t *)self;
|
|
256
|
+
VALUE rb_array = array->rb_array;
|
|
257
|
+
long len = RARRAY_LEN(rb_array);
|
|
258
|
+
for (long i = 0; i < len; i++) {
|
|
259
|
+
mongory_value *mg_val = rb_to_mongory_value_shallow(self->pool, rb_ary_entry(rb_array, i));
|
|
260
|
+
if (!callback(mg_val, acc)) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
|
|
208
267
|
mongory_value *rb_mongory_array_wrap(mongory_memory_pool *pool, VALUE rb_array) {
|
|
209
268
|
rb_mongory_array_t *array = MG_ALLOC_PTR(pool, rb_mongory_array_t);
|
|
269
|
+
if (!array) {
|
|
270
|
+
return NULL;
|
|
271
|
+
}
|
|
272
|
+
memset(array, 0, sizeof(rb_mongory_array_t));
|
|
210
273
|
rb_mongory_memory_pool_t *rb_pool = (rb_mongory_memory_pool_t *)pool;
|
|
211
274
|
array->base.pool = pool;
|
|
212
275
|
array->base.get = rb_mongory_array_get;
|
|
276
|
+
array->base.each = rb_mongory_array_each;
|
|
213
277
|
array->rb_array = rb_array;
|
|
214
278
|
array->base.count = RARRAY_LEN(rb_array);
|
|
215
279
|
array->owner = rb_pool->owner;
|
|
216
280
|
mongory_value *mg_value = mongory_value_wrap_a(pool, &array->base);
|
|
281
|
+
if (!mg_value) {
|
|
282
|
+
return NULL;
|
|
283
|
+
}
|
|
217
284
|
mg_value->origin = (void *)rb_array;
|
|
218
285
|
mg_value->to_str = rb_mongory_value_to_cstr;
|
|
219
286
|
return mg_value;
|
data/lib/core/2.6/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/2.7/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/3.0/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/3.1/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/3.2/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/3.3/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/3.4/mongory_ext.so
CHANGED
|
Binary file
|
data/lib/core/4.0/mongory_ext.so
CHANGED
|
Binary file
|
|
@@ -5,7 +5,7 @@ module Mongory
|
|
|
5
5
|
# ConditionConverter transforms a flat condition hash into nested hash form.
|
|
6
6
|
# This is used internally by ValueConverter to normalize condition structures
|
|
7
7
|
# like { "foo.bar" => 1, "foo.baz" => 2 } into nested Mongo-style conditions.
|
|
8
|
-
# Used by
|
|
8
|
+
# Used by Matcher to normalize condition input for internal matching.
|
|
9
9
|
#
|
|
10
10
|
# Combines key transformation (via KeyConverter) and
|
|
11
11
|
# value normalization (via ValueConverter), and merges overlapping keys.
|
data/lib/mongory/matcher.rb
CHANGED
|
@@ -14,10 +14,6 @@ module Mongory
|
|
|
14
14
|
# @param context [Utils::Context] optional query context
|
|
15
15
|
# @return [Mongory::Matcher] a new matcher
|
|
16
16
|
# @note This method is implemented in the C extension
|
|
17
|
-
# @!method self.trace_result_colorful=(colorful)
|
|
18
|
-
# @param colorful [Boolean] whether to enable colorful trace result
|
|
19
|
-
# @return [void]
|
|
20
|
-
# @note This method is implemented in the C extension
|
|
21
17
|
#
|
|
22
18
|
# @!method match?(record)
|
|
23
19
|
# @param record [Object] the record to match against
|
|
@@ -39,15 +35,6 @@ module Mongory
|
|
|
39
35
|
# @return [Boolean] true if the record matches the condition, false otherwise
|
|
40
36
|
# @note Prints the matching process to STDOUT
|
|
41
37
|
# @note This method is implemented in the C extension
|
|
42
|
-
# @!method enable_trace
|
|
43
|
-
# @return [void]
|
|
44
|
-
# @note This method is implemented in the C extension
|
|
45
|
-
# @!method disable_trace
|
|
46
|
-
# @return [void]
|
|
47
|
-
# @note This method is implemented in the C extension
|
|
48
|
-
# @!method print_trace
|
|
49
|
-
# @return [void]
|
|
50
|
-
# @note This method is implemented in the C extension
|
|
51
38
|
# @!method condition
|
|
52
39
|
# @return [Hash] the normalized condition
|
|
53
40
|
# @note This method is implemented in the C extension
|
|
@@ -49,8 +49,6 @@ module Mongory
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
alias_method :fast, :each
|
|
53
|
-
|
|
54
52
|
# Traces matcher evaluation for all records and returns an Array of structured trace tree Hashes.
|
|
55
53
|
# If a block is given, matched records are also yielded.
|
|
56
54
|
#
|
|
@@ -193,7 +191,7 @@ module Mongory
|
|
|
193
191
|
# @return [QueryBuilder] A new query builder instance with merged context
|
|
194
192
|
# @note Creates a new query builder with the current matcher's condition and merged context
|
|
195
193
|
# @example
|
|
196
|
-
# query.with_context(
|
|
194
|
+
# query.with_context(tenant: current_tenant) #=> Returns a new query builder with merged context
|
|
197
195
|
def with_context(addon_context = {})
|
|
198
196
|
dup_instance_exec do
|
|
199
197
|
@context = @context.dup
|
|
@@ -2,35 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
module Mongory
|
|
4
4
|
module Utils
|
|
5
|
-
# Context is a utility class that provides a stable
|
|
6
|
-
#
|
|
7
|
-
# and the current record being
|
|
5
|
+
# Context is a utility class that provides a stable, mutable shared context
|
|
6
|
+
# for the Mongory query builder and custom matchers. It holds user-defined
|
|
7
|
+
# configuration and the current record being processed.
|
|
8
8
|
#
|
|
9
9
|
# @example
|
|
10
|
-
# context = Mongory::Utils::Context.new(
|
|
10
|
+
# context = Mongory::Utils::Context.new(tenant: current_tenant)
|
|
11
11
|
# context.current_record = record
|
|
12
|
-
# context.config = new_config
|
|
13
12
|
#
|
|
14
|
-
# @attr [
|
|
15
|
-
# @attr [
|
|
16
|
-
# @attr [Boolean] need_convert Whether the record needs to be converted before matching
|
|
13
|
+
# @attr [Hash] config The configuration hash for the context
|
|
14
|
+
# @attr [Object] current_record The current record being processed
|
|
17
15
|
class Context
|
|
18
|
-
attr_accessor :config, :current_record
|
|
16
|
+
attr_accessor :config, :current_record
|
|
19
17
|
|
|
20
18
|
# Initializes a new Context instance with the given configuration.
|
|
21
19
|
#
|
|
22
|
-
# @param config [
|
|
20
|
+
# @param config [Hash] The configuration hash for the context.
|
|
23
21
|
# @return [Context] A new Context instance.
|
|
24
22
|
def initialize(config = {})
|
|
25
23
|
@config = config
|
|
26
24
|
@current_record = nil
|
|
27
|
-
@need_convert = true
|
|
28
25
|
end
|
|
29
26
|
|
|
30
|
-
# Creates a duplicate of the context with its own configuration.
|
|
27
|
+
# Creates a duplicate of the context with its own configuration hash.
|
|
31
28
|
#
|
|
32
29
|
# @return [Context] A new context instance with duplicated configuration
|
|
33
|
-
# @note The new context shares the same configuration object but has its own state
|
|
34
30
|
def dup
|
|
35
31
|
new_context = super
|
|
36
32
|
new_context.config = @config.dup
|
|
@@ -39,8 +35,7 @@ module Mongory
|
|
|
39
35
|
|
|
40
36
|
def to_hash
|
|
41
37
|
{
|
|
42
|
-
config: @config
|
|
43
|
-
need_convert: @need_convert
|
|
38
|
+
config: @config
|
|
44
39
|
}
|
|
45
40
|
end
|
|
46
41
|
end
|
|
@@ -18,16 +18,6 @@ module Mongory
|
|
|
18
18
|
|
|
19
19
|
module_function
|
|
20
20
|
|
|
21
|
-
# Recursively marks an explain_tree node and all descendants with `result: :skip`.
|
|
22
|
-
#
|
|
23
|
-
# @param node [Hash] structured explain_tree node
|
|
24
|
-
# @return [Hash] structured trace_tree node with `result: :skip`
|
|
25
|
-
def mark_skipped(node)
|
|
26
|
-
skipped = node.merge(result: :skip)
|
|
27
|
-
skipped[:children] = (node[:children] || []).map { |child| mark_skipped(child) }
|
|
28
|
-
skipped
|
|
29
|
-
end
|
|
30
|
-
|
|
31
21
|
# Prints a structured explain_tree Hash to STDOUT.
|
|
32
22
|
#
|
|
33
23
|
# @param node [Hash] root explain_tree node
|
data/lib/mongory/version.rb
CHANGED
data/lib/mongory.rb
CHANGED
|
@@ -74,22 +74,33 @@ module Mongory
|
|
|
74
74
|
@condition_converter ||= Converters::ConditionConverter.instance
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
# Builds a new query over the given record set.
|
|
77
|
+
# Builds a new query builder over the given record set.
|
|
78
|
+
#
|
|
79
|
+
# @example
|
|
80
|
+
# Mongory.query(records).where(:age.gte => 18).pluck(:name)
|
|
78
81
|
#
|
|
79
82
|
# @param records [Enumerable] any enumerable object (Array, AR::Relation, etc.)
|
|
80
83
|
# @return [QueryBuilder] a new query builder
|
|
81
|
-
def self.
|
|
84
|
+
def self.query(records)
|
|
82
85
|
QueryBuilder.new(records)
|
|
83
86
|
end
|
|
84
87
|
|
|
85
|
-
|
|
88
|
+
singleton_class.alias_method :build_query, :query
|
|
89
|
+
|
|
90
|
+
# Compiles a reusable matcher for the given condition.
|
|
91
|
+
#
|
|
92
|
+
# @example
|
|
93
|
+
# ADULT = Mongory.compile(:age.gte => 18)
|
|
94
|
+
# ADULT.match?(age: 20) #=> true
|
|
86
95
|
#
|
|
87
96
|
# @param condition [Hash] the query condition
|
|
88
|
-
# @return [Matcher] a new matcher
|
|
89
|
-
def self.
|
|
97
|
+
# @return [Matcher] a new compiled matcher
|
|
98
|
+
def self.compile(condition)
|
|
90
99
|
Matcher.new(condition)
|
|
91
100
|
end
|
|
92
101
|
|
|
102
|
+
singleton_class.alias_method :build_matcher, :compile
|
|
103
|
+
|
|
93
104
|
# Registers a class to support `.mongory` query DSL.
|
|
94
105
|
# This injects a `#mongory` method into the given class.
|
|
95
106
|
#
|
|
@@ -123,6 +134,17 @@ module Mongory
|
|
|
123
134
|
end
|
|
124
135
|
|
|
125
136
|
abi = RUBY_VERSION.split('.').first(2).join('.')
|
|
126
|
-
|
|
137
|
+
begin
|
|
138
|
+
require_relative "core/#{abi}/mongory_ext"
|
|
139
|
+
rescue LoadError
|
|
140
|
+
require 'mongory_ext'
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
unless defined?(Mongory::Matcher) && Mongory::Matcher.method_defined?(:match?)
|
|
144
|
+
raise LoadError,
|
|
145
|
+
"Incompatible or outdated mongory_ext loaded for Ruby #{abi} (Mongory::Matcher not defined). " \
|
|
146
|
+
'Please recompile the C extension (e.g. `bundle exec rake compile`).'
|
|
147
|
+
end
|
|
148
|
+
|
|
127
149
|
require_relative 'mongory/matcher'
|
|
128
150
|
require_relative 'mongory/query_builder'
|
data/renovate.json
ADDED
data/scripts/build_with_core.sh
CHANGED
|
@@ -99,7 +99,6 @@ init_submodules() {
|
|
|
99
99
|
# Function to build mongory-core if needed
|
|
100
100
|
build_core() {
|
|
101
101
|
# mongory-rb 直接由 extconf.rb 編譯 mongory-core 的源碼,不需要獨立建置靜態庫
|
|
102
|
-
# 同時避免觸發 mongory-core 的 CMake(其需要 cJSON 僅用於測試)
|
|
103
102
|
log $YELLOW "Skipping mongory-core standalone build (not required for mongory-rb)"
|
|
104
103
|
}
|
|
105
104
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- koten0224
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A Mongo-like in-memory query DSL for Ruby
|
|
14
14
|
email:
|
|
@@ -116,6 +116,7 @@ files:
|
|
|
116
116
|
- lib/mongory/utils/tree_renderer.rb
|
|
117
117
|
- lib/mongory/version.rb
|
|
118
118
|
- mongory.gemspec
|
|
119
|
+
- renovate.json
|
|
119
120
|
- script/bench.rb
|
|
120
121
|
- scripts/build_with_core.sh
|
|
121
122
|
- sig/mongory.rbs
|