mongory 0.7.2-arm64-darwin-23

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 (115) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +88 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +364 -0
  6. data/CODE_OF_CONDUCT.md +84 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +488 -0
  9. data/Rakefile +107 -0
  10. data/SUBMODULE_INTEGRATION.md +325 -0
  11. data/docs/advanced_usage.md +40 -0
  12. data/docs/clang_bridge.md +69 -0
  13. data/docs/field_names.md +30 -0
  14. data/docs/migration.md +30 -0
  15. data/docs/performance.md +61 -0
  16. data/examples/README.md +41 -0
  17. data/examples/benchmark-rails.rb +52 -0
  18. data/examples/benchmark.rb +184 -0
  19. data/ext/mongory_ext/extconf.rb +91 -0
  20. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +122 -0
  21. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +161 -0
  22. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +79 -0
  23. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +95 -0
  24. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +127 -0
  25. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +175 -0
  26. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +76 -0
  27. data/ext/mongory_ext/mongory-core/include/mongory-core.h +12 -0
  28. data/ext/mongory_ext/mongory-core/src/foundations/array.c +287 -0
  29. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +19 -0
  30. data/ext/mongory_ext/mongory-core/src/foundations/config.c +270 -0
  31. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +48 -0
  32. data/ext/mongory_ext/mongory-core/src/foundations/error.c +38 -0
  33. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +298 -0
  34. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +65 -0
  35. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +49 -0
  36. data/ext/mongory_ext/mongory-core/src/foundations/table.c +498 -0
  37. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +210 -0
  38. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +70 -0
  39. data/ext/mongory_ext/mongory-core/src/foundations/value.c +500 -0
  40. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +164 -0
  41. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h +47 -0
  42. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +122 -0
  43. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +100 -0
  44. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +217 -0
  45. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +83 -0
  46. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +573 -0
  47. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +125 -0
  48. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +147 -0
  49. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.h +48 -0
  50. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +124 -0
  51. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +46 -0
  52. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +126 -0
  53. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +46 -0
  54. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +314 -0
  55. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h +97 -0
  56. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +252 -0
  57. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +79 -0
  58. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +23 -0
  59. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +60 -0
  60. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +23 -0
  61. data/ext/mongory_ext/mongory_ext.c +683 -0
  62. data/lib/generators/mongory/install/install_generator.rb +42 -0
  63. data/lib/generators/mongory/install/templates/initializer.rb.erb +83 -0
  64. data/lib/generators/mongory/matcher/matcher_generator.rb +56 -0
  65. data/lib/generators/mongory/matcher/templates/matcher.rb.erb +92 -0
  66. data/lib/generators/mongory/matcher/templates/matcher_spec.rb.erb +17 -0
  67. data/lib/mongory/c_query_builder.rb +44 -0
  68. data/lib/mongory/converters/abstract_converter.rb +111 -0
  69. data/lib/mongory/converters/condition_converter.rb +64 -0
  70. data/lib/mongory/converters/converted.rb +81 -0
  71. data/lib/mongory/converters/data_converter.rb +37 -0
  72. data/lib/mongory/converters/key_converter.rb +87 -0
  73. data/lib/mongory/converters/value_converter.rb +52 -0
  74. data/lib/mongory/converters.rb +8 -0
  75. data/lib/mongory/matchers/abstract_matcher.rb +219 -0
  76. data/lib/mongory/matchers/abstract_multi_matcher.rb +124 -0
  77. data/lib/mongory/matchers/and_matcher.rb +72 -0
  78. data/lib/mongory/matchers/array_record_matcher.rb +93 -0
  79. data/lib/mongory/matchers/elem_match_matcher.rb +55 -0
  80. data/lib/mongory/matchers/eq_matcher.rb +46 -0
  81. data/lib/mongory/matchers/every_matcher.rb +56 -0
  82. data/lib/mongory/matchers/exists_matcher.rb +53 -0
  83. data/lib/mongory/matchers/field_matcher.rb +147 -0
  84. data/lib/mongory/matchers/gt_matcher.rb +41 -0
  85. data/lib/mongory/matchers/gte_matcher.rb +41 -0
  86. data/lib/mongory/matchers/hash_condition_matcher.rb +62 -0
  87. data/lib/mongory/matchers/in_matcher.rb +68 -0
  88. data/lib/mongory/matchers/literal_matcher.rb +121 -0
  89. data/lib/mongory/matchers/lt_matcher.rb +41 -0
  90. data/lib/mongory/matchers/lte_matcher.rb +41 -0
  91. data/lib/mongory/matchers/ne_matcher.rb +38 -0
  92. data/lib/mongory/matchers/nin_matcher.rb +68 -0
  93. data/lib/mongory/matchers/not_matcher.rb +40 -0
  94. data/lib/mongory/matchers/or_matcher.rb +68 -0
  95. data/lib/mongory/matchers/present_matcher.rb +55 -0
  96. data/lib/mongory/matchers/regex_matcher.rb +80 -0
  97. data/lib/mongory/matchers/size_matcher.rb +54 -0
  98. data/lib/mongory/matchers.rb +176 -0
  99. data/lib/mongory/mongoid.rb +19 -0
  100. data/lib/mongory/query_builder.rb +257 -0
  101. data/lib/mongory/query_matcher.rb +93 -0
  102. data/lib/mongory/query_operator.rb +28 -0
  103. data/lib/mongory/rails.rb +15 -0
  104. data/lib/mongory/utils/context.rb +48 -0
  105. data/lib/mongory/utils/debugger.rb +125 -0
  106. data/lib/mongory/utils/rails_patch.rb +22 -0
  107. data/lib/mongory/utils/singleton_builder.rb +31 -0
  108. data/lib/mongory/utils.rb +76 -0
  109. data/lib/mongory/version.rb +5 -0
  110. data/lib/mongory.rb +123 -0
  111. data/lib/mongory_ext.bundle +0 -0
  112. data/mongory.gemspec +50 -0
  113. data/scripts/build_with_core.sh +292 -0
  114. data/sig/mongory.rbs +4 -0
  115. metadata +164 -0
@@ -0,0 +1,79 @@
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 "literal_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
+ return mongory_string_cpyf(pool, "%s: %s",
15
+ matcher->name,
16
+ condition->to_str(condition, pool)
17
+ );
18
+ }
19
+
20
+ char *mongory_matcher_title_with_field(mongory_matcher *matcher, mongory_memory_pool *pool) {
21
+ mongory_field_matcher *field_matcher = (mongory_field_matcher *)matcher;
22
+ mongory_value *condition = matcher->condition;
23
+ return mongory_string_cpyf(pool, "Field: \"%s\", to match: %s",
24
+ field_matcher->field,
25
+ condition->to_str(condition, pool)
26
+ );
27
+ }
28
+
29
+ static inline char *mongory_matcher_tail_connection(int count, int total) {
30
+ if (total == 0) {
31
+ return "";
32
+ }
33
+ if (total - count == 1) {
34
+ return "└─ ";
35
+ }
36
+ return "├─ ";
37
+ }
38
+
39
+ static inline char *mongory_matcher_indent_connection(int count, int total) {
40
+ if (total == 0) {
41
+ return "";
42
+ }
43
+ if (total - count == 1) {
44
+ return " ";
45
+ }
46
+ return "│ ";
47
+ }
48
+
49
+ bool mongory_matcher_base_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
50
+ char *connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
51
+ char *title = mongory_matcher_title(matcher, ctx->pool);
52
+ char *prefix = (char *)ctx->acc;
53
+ printf("%s%s%s\n", prefix, connection, title);
54
+ return true;
55
+ }
56
+
57
+ bool mongory_matcher_composite_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
58
+ mongory_matcher_base_explain(matcher, ctx);
59
+ char *prefix = (char *)ctx->acc;
60
+ char *indent = mongory_matcher_indent_connection(ctx->count, ctx->total);
61
+ ctx->acc = mongory_string_cpyf(ctx->pool, "%s%s", prefix, indent);
62
+ return true;
63
+ }
64
+
65
+ bool mongory_matcher_literal_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
66
+ return mongory_matcher_composite_explain(matcher, ctx);
67
+ }
68
+
69
+ bool mongory_matcher_field_explain(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
70
+ char *tail_connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
71
+ char *title = mongory_matcher_title_with_field(matcher, ctx->pool);
72
+ char *prefix = (char *)ctx->acc;
73
+ printf("%s%s%s\n", prefix, tail_connection, title);
74
+ char *indent = mongory_matcher_indent_connection(ctx->count, ctx->total);
75
+ ctx->acc = mongory_string_cpyf(ctx->pool, "%s%s", prefix, indent);
76
+ return true;
77
+ }
78
+
79
+ #endif /* MONGORY_MATCHER_EXPLAINABLE_C */
@@ -0,0 +1,23 @@
1
+ #ifndef MONGORY_MATCHER_EXPLAINABLE_H
2
+ #define MONGORY_MATCHER_EXPLAINABLE_H
3
+
4
+ #include "mongory-core/matchers/matcher.h"
5
+ #include "matcher_traversable.h"
6
+ #include <mongory-core.h>
7
+
8
+
9
+ /**
10
+ * @brief Explains a matcher.
11
+ * @param matcher The matcher to explain.
12
+ * @param ctx The context to use for the explanation.
13
+ */
14
+
15
+ bool mongory_matcher_base_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
16
+
17
+ bool mongory_matcher_composite_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
18
+
19
+ bool mongory_matcher_field_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
20
+
21
+ bool mongory_matcher_literal_explain(struct mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
22
+
23
+ #endif /* MONGORY_MATCHER_EXPLAINABLE_H */
@@ -0,0 +1,60 @@
1
+ #ifndef MONGORY_MATCHER_TRAVERSABLE_C
2
+ #define MONGORY_MATCHER_TRAVERSABLE_C
3
+
4
+ #include "matcher_traversable.h"
5
+ #include "base_matcher.h"
6
+ #include "composite_matcher.h"
7
+ #include "literal_matcher.h"
8
+
9
+ bool mongory_matcher_leaf_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
10
+ bool continue_traverse = ctx->callback(matcher, ctx);
11
+ if (!continue_traverse)
12
+ return false;
13
+ ctx->count++;
14
+ return true;
15
+ }
16
+
17
+ bool mongory_matcher_composite_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
18
+ void *prev_acc = ctx->acc;
19
+ if (!mongory_matcher_leaf_traverse(matcher, ctx))
20
+ return false;
21
+ mongory_composite_matcher *composite = (mongory_composite_matcher *)matcher;
22
+ mongory_array *children = composite->children;
23
+ int total = (int)children->count;
24
+ mongory_matcher_traverse_context child_ctx = {
25
+ .pool = ctx->pool,
26
+ .level = ctx->level + 1,
27
+ .count = 0,
28
+ .total = total,
29
+ .acc = ctx->acc,
30
+ .callback = ctx->callback,
31
+ };
32
+
33
+ for (int i = 0; i < total; i++) {
34
+ mongory_matcher *child = (mongory_matcher *)children->get(children, i);
35
+ if (!child->traverse(child, &child_ctx))
36
+ return false;
37
+ }
38
+ ctx->acc = prev_acc;
39
+ return true;
40
+ }
41
+
42
+ bool mongory_matcher_literal_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
43
+ void *prev_acc = ctx->acc;
44
+ if (!mongory_matcher_leaf_traverse(matcher, ctx))
45
+ return false;
46
+ mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
47
+ mongory_matcher *next_matcher = literal->array_record_matcher ? literal->array_record_matcher : literal->delegate_matcher;
48
+ mongory_matcher_traverse_context child_ctx = {
49
+ .pool = ctx->pool,
50
+ .level = ctx->level + 1,
51
+ .count = 0,
52
+ .total = 1,
53
+ .acc = ctx->acc,
54
+ .callback = ctx->callback,
55
+ };
56
+ bool result = next_matcher->traverse(next_matcher, &child_ctx);
57
+ ctx->acc = prev_acc;
58
+ return result;
59
+ }
60
+ #endif /* MONGORY_MATCHER_TRAVERSABLE_C */
@@ -0,0 +1,23 @@
1
+ #ifndef MONGORY_MATCHER_TRAVERSABLE_H
2
+ #define MONGORY_MATCHER_TRAVERSABLE_H
3
+
4
+ #include "mongory-core/matchers/matcher.h"
5
+
6
+ typedef struct mongory_matcher_traverse_context mongory_matcher_traverse_context;
7
+ typedef bool (*mongory_matcher_traverse_func)(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
8
+ struct mongory_matcher_traverse_context {
9
+ mongory_memory_pool *pool;
10
+ int level;
11
+ int count;
12
+ int total;
13
+ void *acc;
14
+ mongory_matcher_traverse_func callback;
15
+ } ;
16
+
17
+ bool mongory_matcher_leaf_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
18
+
19
+ bool mongory_matcher_composite_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
20
+
21
+ bool mongory_matcher_literal_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
22
+
23
+ #endif /* MONGORY_MATCHER_TRAVERSABLE_H */