mongory 2.1.0 → 2.2.0

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +55 -73
  4. data/docs/clang_bridge.md +2 -2
  5. data/docs/performance.md +43 -7
  6. data/ext/mongory_ext/extconf.rb +15 -0
  7. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +28 -43
  8. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +0 -1
  9. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +3 -4
  10. data/ext/mongory_ext/mongory-core/src/foundations/array.c +28 -5
  11. data/ext/mongory_ext/mongory-core/src/foundations/config.c +24 -22
  12. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +3 -3
  13. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +22 -13
  14. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +4 -3
  15. data/ext/mongory_ext/mongory-core/src/foundations/table.c +60 -224
  16. data/ext/mongory_ext/mongory-core/src/foundations/table_private.h +36 -0
  17. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +30 -47
  18. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +2 -5
  19. data/ext/mongory_ext/mongory-core/src/foundations/value.c +18 -32
  20. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +89 -104
  21. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +18 -11
  22. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +35 -150
  23. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +244 -418
  24. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +30 -0
  25. data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.c +15 -56
  26. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +18 -39
  27. data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.c +14 -15
  28. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +382 -74
  29. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +373 -123
  30. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +20 -12
  31. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +1 -4
  32. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.c +214 -171
  33. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.h +8 -16
  34. data/ext/mongory_ext/mongory_ext.c +26 -4
  35. data/ext/mongory_ext/mongory_ext_internal.h +15 -3
  36. data/ext/mongory_ext/rb_mongory_adapters.c +52 -19
  37. data/ext/mongory_ext/rb_mongory_matcher.c +115 -36
  38. data/ext/mongory_ext/rb_mongory_value.c +124 -51
  39. data/lib/mongory/converters/abstract_converter.rb +5 -5
  40. data/lib/mongory/converters/converted.rb +0 -4
  41. data/lib/mongory/converters/key_converter.rb +13 -36
  42. data/lib/mongory/converters/value_converter.rb +4 -4
  43. data/lib/mongory/matchers.rb +8 -7
  44. data/lib/mongory/query_builder.rb +9 -0
  45. data/lib/mongory/utils/context.rb +0 -6
  46. data/lib/mongory/utils/singleton_builder.rb +1 -4
  47. data/lib/mongory/version.rb +1 -1
  48. data/lib/mongory.rb +0 -1
  49. data/script/bench.rb +77 -4
  50. data/script/coverage.rb +84 -0
  51. metadata +7 -7
  52. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +0 -117
  53. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +0 -29
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'coverage'
4
+
5
+ # Prints per-file and total Ruby line/branch coverage using stdlib Coverage (zero gem deps).
6
+ module MongoryCoverageReporter
7
+ ROW_FORMAT = "%<label>-42s Line: %<lp>5.1f%% (%<hit_l>3d/%<tot_l>3d) Branch: %<bp>5.1f%% (%<hit_b>3d/%<tot_b>3d)\n"
8
+
9
+ def self.summarize(result, lib_root)
10
+ totals = { hit_l: 0, tot_l: 0, hit_b: 0, tot_b: 0 }
11
+ result.select { |path, _| path.start_with?(lib_root) }.sort.each do |file, data|
12
+ print_file_row(file.sub("#{lib_root}/", ''), data, totals)
13
+ end
14
+ print_row('TOTAL', totals)
15
+ totals
16
+ end
17
+
18
+ def self.print_file_row(rel, data, totals)
19
+ row = count_hits(data)
20
+ row.each { |k, v| totals[k] += v }
21
+ print_row(rel, row)
22
+ end
23
+
24
+ def self.count_hits(data)
25
+ lines = data[:lines].compact
26
+ branches = data[:branches].values.flat_map(&:values)
27
+ { hit_l: lines.count(&:positive?), tot_l: lines.size, hit_b: branches.count(&:positive?), tot_b: branches.size }
28
+ end
29
+
30
+ def self.pct(hit, total)
31
+ total.positive? ? (hit * 100.0 / total) : 100.0
32
+ end
33
+
34
+ def self.print_row(label, counts)
35
+ printf(ROW_FORMAT, counts.merge(label: label,
36
+ lp: pct(counts[:hit_l], counts[:tot_l]),
37
+ bp: pct(counts[:hit_b], counts[:tot_b])))
38
+ end
39
+
40
+ def self.write_lcov(result, lib_root, out_path)
41
+ return if out_path.nil? || out_path.empty?
42
+
43
+ repo_root = File.expand_path('..', lib_root)
44
+ File.open(out_path, 'w') do |io|
45
+ result.select { |path, _| path.start_with?(lib_root) }.sort.each do |file, data|
46
+ write_lcov_record(io, file.sub("#{repo_root}/", ''), data[:lines])
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.write_lcov_record(io, rel_path, lines)
52
+ io.puts("SF:#{rel_path}")
53
+ lines.each_with_index { |hits, idx| io.puts("DA:#{idx + 1},#{hits}") unless hits.nil? }
54
+ io.puts('end_of_record')
55
+ end
56
+
57
+ def self.enforce_threshold!(totals)
58
+ min_line = Float(ENV.fetch('MIN_LINE_COVERAGE', '0'))
59
+ return if min_line <= 0 || totals[:tot_l].zero?
60
+
61
+ actual = totals[:hit_l] * 100.0 / totals[:tot_l]
62
+ return if actual >= min_line
63
+
64
+ warn format('ERROR: Ruby line coverage %<actual>.1f%% is below threshold %<min>.1f%%',
65
+ actual: actual, min: min_line)
66
+ exit(1)
67
+ end
68
+ end
69
+
70
+ Coverage.start(lines: true, branches: true)
71
+
72
+ at_exit do
73
+ status = $ERROR_INFO
74
+ next if status.is_a?(SystemExit) && !status.success?
75
+
76
+ result = Coverage.result
77
+ lib_root = File.expand_path('../lib', __dir__)
78
+ totals = MongoryCoverageReporter.summarize(result, lib_root)
79
+ MongoryCoverageReporter.write_lcov(result, lib_root, ENV.fetch('LCOV_OUT', nil))
80
+ MongoryCoverageReporter.enforce_threshold!(totals)
81
+ end
82
+
83
+ ARGV.replace(%w(spec --format progress)) if ARGV.empty?
84
+ load Gem.bin_path('rspec-core', 'rspec')
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.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - koten0224
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-23 00:00:00.000000000 Z
11
+ date: 2026-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Mongo-like in-memory query DSL for Ruby
14
14
  email:
@@ -55,6 +55,7 @@ files:
55
55
  - ext/mongory_ext/mongory-core/src/foundations/string_buffer.c
56
56
  - ext/mongory_ext/mongory-core/src/foundations/string_buffer.h
57
57
  - ext/mongory_ext/mongory-core/src/foundations/table.c
58
+ - ext/mongory_ext/mongory-core/src/foundations/table_private.h
58
59
  - ext/mongory_ext/mongory-core/src/foundations/utils.c
59
60
  - ext/mongory_ext/mongory-core/src/foundations/utils.h
60
61
  - ext/mongory_ext/mongory-core/src/foundations/value.c
@@ -73,8 +74,6 @@ files:
73
74
  - ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c
74
75
  - ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h
75
76
  - ext/mongory_ext/mongory-core/src/matchers/matcher.c
76
- - ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c
77
- - ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h
78
77
  - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c
79
78
  - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h
80
79
  - ext/mongory_ext/mongory-core/src/matchers/value_matcher.c
@@ -110,6 +109,7 @@ files:
110
109
  - lib/mongory/version.rb
111
110
  - renovate.json
112
111
  - script/bench.rb
112
+ - script/coverage.rb
113
113
  - scripts/build_with_core.sh
114
114
  - sig/mongory.rbs
115
115
  homepage: https://mongoryhq.github.io/mongory-rb/
@@ -121,7 +121,7 @@ metadata:
121
121
  homepage_uri: https://mongoryhq.github.io/mongory-rb/
122
122
  source_code_uri: https://github.com/mongoryhq/mongory-rb
123
123
  changelog_uri: https://github.com/mongoryhq/mongory-rb/blob/main/CHANGELOG.md
124
- post_install_message:
124
+ post_install_message:
125
125
  rdoc_options: []
126
126
  require_paths:
127
127
  - lib
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubygems_version: 3.4.19
140
- signing_key:
140
+ signing_key:
141
141
  specification_version: 4
142
142
  summary: MongoDB-like in-memory query DSL for Ruby
143
143
  test_files: []
@@ -1,117 +0,0 @@
1
- #ifndef MONGORY_MATCHER_EXPLAINABLE_C
2
- #define MONGORY_MATCHER_EXPLAINABLE_C
3
-
4
- #include "matcher_explainable.h"
5
- #include "../foundations/string_buffer.h"
6
- #include "base_matcher.h"
7
- #include "composite_matcher.h"
8
- #include "value_matcher.h"
9
- #include "../foundations/utils.h"
10
- #include <stdio.h>
11
-
12
- char *mongory_matcher_title(mongory_matcher *matcher, mongory_memory_pool *pool) {
13
- mongory_value *condition = matcher->condition;
14
- char *cond_str = (condition && condition->to_str) ? condition->to_str(condition, pool) : NULL;
15
- if (!cond_str) {
16
- return NULL;
17
- }
18
- return mongory_string_cpyf(pool, "%s: %s",
19
- matcher->name ? matcher->name : "",
20
- cond_str
21
- );
22
- }
23
-
24
- char *mongory_matcher_title_with_field(mongory_matcher *matcher, mongory_memory_pool *pool) {
25
- mongory_field_matcher *field_matcher = (mongory_field_matcher *)matcher;
26
- mongory_value *condition = matcher->condition;
27
- char *cond_str = (condition && condition->to_str) ? condition->to_str(condition, pool) : NULL;
28
- if (!cond_str) {
29
- return NULL;
30
- }
31
- return mongory_string_cpyf(pool, "Field: \"%s\", to match: %s",
32
- field_matcher->field ? field_matcher->field : "",
33
- cond_str
34
- );
35
- }
36
-
37
- static inline char *mongory_matcher_tail_connection(int count, int total) {
38
- if (total == 0) {
39
- return "";
40
- }
41
- if (total - count == 1) {
42
- return "└─ ";
43
- }
44
- return "├─ ";
45
- }
46
-
47
- static inline char *mongory_matcher_indent_connection(int count, int total) {
48
- if (total == 0) {
49
- return "";
50
- }
51
- if (total - count == 1) {
52
- return " ";
53
- }
54
- return "│ ";
55
- }
56
-
57
- static mongory_explain_acc *mongory_explain_acc_child(
58
- mongory_memory_pool *pool,
59
- mongory_explain_acc *parent_acc,
60
- int count,
61
- int total
62
- ) {
63
- char *indent = mongory_matcher_indent_connection(count, total);
64
- mongory_explain_acc *next = MG_ALLOC_PTR(pool, mongory_explain_acc);
65
- if (!next) {
66
- return NULL;
67
- }
68
- next->prefix = mongory_string_cpyf(pool, "%s%s", parent_acc->prefix, indent);
69
- if (!next->prefix) {
70
- return NULL;
71
- }
72
- next->buf = parent_acc->buf;
73
- return next;
74
- }
75
-
76
- static bool mongory_matcher_append_explain_line(
77
- mongory_matcher_traverse_context *ctx,
78
- char *title
79
- ) {
80
- mongory_explain_acc *acc = (mongory_explain_acc *)ctx->acc;
81
- char *connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
82
- if (!acc || !acc->buf || !title) {
83
- return false;
84
- }
85
- mongory_string_buffer_appendf(acc->buf, "%s%s%s\n", acc->prefix, connection, title);
86
- return ctx->pool->error == NULL;
87
- }
88
-
89
- bool mongory_matcher_base_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
90
- char *title = mongory_matcher_title(matcher, ctx->pool);
91
- return mongory_matcher_append_explain_line(ctx, title);
92
- }
93
-
94
- bool mongory_matcher_composite_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
95
- if (!mongory_matcher_base_explain(matcher, ctx)) {
96
- return false;
97
- }
98
- mongory_explain_acc *acc = (mongory_explain_acc *)ctx->acc;
99
- ctx->acc = mongory_explain_acc_child(ctx->pool, acc, ctx->count, ctx->total);
100
- return ctx->acc != NULL;
101
- }
102
-
103
- bool mongory_matcher_value_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
104
- return mongory_matcher_composite_explain(matcher, ctx);
105
- }
106
-
107
- bool mongory_matcher_field_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
108
- char *title = mongory_matcher_title_with_field(matcher, ctx->pool);
109
- if (!mongory_matcher_append_explain_line(ctx, title)) {
110
- return false;
111
- }
112
- mongory_explain_acc *acc = (mongory_explain_acc *)ctx->acc;
113
- ctx->acc = mongory_explain_acc_child(ctx->pool, acc, ctx->count, ctx->total);
114
- return ctx->acc != NULL;
115
- }
116
-
117
- #endif /* MONGORY_MATCHER_EXPLAINABLE_C */
@@ -1,29 +0,0 @@
1
- #ifndef MONGORY_MATCHER_EXPLAINABLE_H
2
- #define MONGORY_MATCHER_EXPLAINABLE_H
3
-
4
- #include "mongory-core/matchers/matcher.h"
5
- #include "../foundations/string_buffer.h"
6
- #include "matcher_traversable.h"
7
- #include <mongory-core.h>
8
-
9
- typedef struct mongory_explain_acc {
10
- char *prefix;
11
- mongory_string_buffer *buf;
12
- } mongory_explain_acc;
13
-
14
-
15
- /**
16
- * @brief Explains a matcher.
17
- * @param matcher The matcher to explain.
18
- * @param ctx The context to use for the explanation.
19
- */
20
-
21
- bool mongory_matcher_base_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
22
-
23
- bool mongory_matcher_composite_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
24
-
25
- bool mongory_matcher_field_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
26
-
27
- bool mongory_matcher_value_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
28
-
29
- #endif /* MONGORY_MATCHER_EXPLAINABLE_H */