mongory 0.7.1 → 0.7.5

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/README.md +34 -0
  4. data/Rakefile +28 -9
  5. data/ext/mongory_ext/mongory_ext.c +77 -29
  6. data/lib/mongory/matchers/in_matcher.rb +2 -2
  7. data/lib/mongory/matchers/nin_matcher.rb +2 -2
  8. data/lib/mongory/version.rb +1 -1
  9. data/lib/mongory.rb +4 -2
  10. metadata +7 -62
  11. data/ext/mongory_ext/mongory-core/LICENSE +0 -3
  12. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +0 -105
  13. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +0 -206
  14. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +0 -82
  15. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +0 -95
  16. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +0 -108
  17. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +0 -175
  18. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +0 -76
  19. data/ext/mongory_ext/mongory-core/include/mongory-core.h +0 -12
  20. data/ext/mongory_ext/mongory-core/src/foundations/array.c +0 -246
  21. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +0 -18
  22. data/ext/mongory_ext/mongory-core/src/foundations/config.c +0 -406
  23. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +0 -30
  24. data/ext/mongory_ext/mongory-core/src/foundations/error.c +0 -30
  25. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +0 -298
  26. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -65
  27. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -49
  28. data/ext/mongory_ext/mongory-core/src/foundations/table.c +0 -458
  29. data/ext/mongory_ext/mongory-core/src/foundations/value.c +0 -459
  30. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +0 -309
  31. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h +0 -47
  32. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +0 -161
  33. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +0 -115
  34. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +0 -210
  35. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +0 -83
  36. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +0 -539
  37. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +0 -125
  38. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +0 -144
  39. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.h +0 -48
  40. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +0 -121
  41. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +0 -46
  42. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +0 -199
  43. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +0 -46
  44. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +0 -334
  45. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h +0 -97
  46. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +0 -198
  47. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +0 -107
  48. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +0 -50
  49. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +0 -55
  50. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +0 -23
  51. data/mongory.gemspec +0 -46
@@ -1,107 +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 "literal_matcher.h"
9
- #include <stdio.h>
10
-
11
- char *mongory_matcher_title(mongory_matcher *matcher, mongory_memory_pool *pool) {
12
- mongory_string_buffer *buffer = mongory_string_buffer_new(pool);
13
- mongory_string_buffer_append(buffer, matcher->name);
14
- mongory_string_buffer_append(buffer, ": ");
15
- mongory_value *condition = matcher->condition;
16
- mongory_string_buffer_append(buffer, condition->to_str(condition, pool));
17
- return mongory_string_buffer_cstr(buffer);
18
- }
19
-
20
- char *mongory_matcher_title_with_field(mongory_matcher *matcher, mongory_memory_pool *pool) {
21
- mongory_string_buffer *buffer = mongory_string_buffer_new(pool);
22
- mongory_field_matcher *field_matcher = (mongory_field_matcher *)matcher;
23
- mongory_string_buffer_appendf(buffer, "Field: \"%s\", to match: ", field_matcher->field);
24
- mongory_value *condition = field_matcher->literal.base.condition;
25
- mongory_string_buffer_append(buffer, condition->to_str(condition, pool));
26
- return mongory_string_buffer_cstr(buffer);
27
- }
28
-
29
- static inline char *mongory_matcher_tail_connection(int count, int total) {
30
- if (count == (total - 1)) {
31
- return "└─ ";
32
- } else if (total == 0) {
33
- return "";
34
- }
35
- return "├─ ";
36
- }
37
-
38
- static inline char *mongory_matcher_indent_connection(int count, int total) {
39
- if (count < total) {
40
- return "│ ";
41
- } else if (total == 0) {
42
- return "";
43
- }
44
- return " ";
45
- }
46
-
47
- void mongory_matcher_base_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
48
- char *connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
49
- ctx->count++;
50
- char *title = mongory_matcher_title(matcher, ctx->pool);
51
- printf("%s%s%s\n", ctx->prefix, connection, title);
52
- }
53
-
54
- void mongory_matcher_traverse_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
55
- mongory_composite_matcher *composite = (mongory_composite_matcher *)matcher;
56
- mongory_array *children = composite->children;
57
- int total = (int)children->count;
58
- for (int i = 0; i < total; i++) {
59
- mongory_matcher *child = (mongory_matcher *)children->get(children, i);
60
- child->explain(child, ctx);
61
- }
62
- }
63
-
64
- void mongory_matcher_composite_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
65
- mongory_matcher_base_explain(matcher, ctx);
66
- mongory_string_buffer *buffer = mongory_string_buffer_new(ctx->pool);
67
- mongory_string_buffer_appendf(buffer, "%s%s", ctx->prefix, mongory_matcher_indent_connection(ctx->count, ctx->total));
68
- mongory_matcher_explain_context child_ctx = {
69
- .pool = ctx->pool,
70
- .count = 0,
71
- .total = matcher->sub_count,
72
- .prefix = mongory_string_buffer_cstr(buffer),
73
- };
74
- mongory_matcher_traverse_explain(matcher, &child_ctx);
75
- }
76
-
77
- static inline void mongory_matcher_literal_shared_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
78
- mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
79
- mongory_string_buffer *buffer = mongory_string_buffer_new(ctx->pool);
80
- mongory_string_buffer_appendf(buffer, "%s%s", ctx->prefix, mongory_matcher_indent_connection(ctx->count, ctx->total));
81
- mongory_matcher_explain_context child_ctx = {
82
- .pool = ctx->pool,
83
- .count = 0,
84
- .total = matcher->sub_count,
85
- .prefix = mongory_string_buffer_cstr(buffer),
86
- };
87
- if (literal->array_record_matcher) {
88
- literal->array_record_matcher->explain(literal->array_record_matcher, &child_ctx);
89
- } else {
90
- literal->delegate_matcher->explain(literal->delegate_matcher, &child_ctx);
91
- }
92
- }
93
-
94
- void mongory_matcher_literal_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
95
- mongory_matcher_base_explain(matcher, ctx);
96
- mongory_matcher_literal_shared_explain(matcher, ctx);
97
- }
98
-
99
- void mongory_matcher_field_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
100
- char *connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
101
- char *title = mongory_matcher_title_with_field(matcher, ctx->pool);
102
- ctx->count++;
103
- printf("%s%s%s\n", ctx->prefix, connection, title);
104
- mongory_matcher_literal_shared_explain(matcher, ctx);
105
- }
106
-
107
- #endif /* MONGORY_MATCHER_EXPLAINABLE_C */
@@ -1,50 +0,0 @@
1
- #ifndef MONGORY_MATCHER_EXPLAINABLE_H
2
- #define MONGORY_MATCHER_EXPLAINABLE_H
3
-
4
- #include "mongory-core/matchers/matcher.h"
5
- #include <mongory-core.h>
6
-
7
- /**
8
- * @brief Context for explaining a matcher.
9
- *
10
- * @param pool The pool to use for the explanation.
11
- * @param count The count of the matcher.
12
- * @param total The total number of matchers.
13
- * @param prefix The prefix to use for the explanation.
14
- */
15
- typedef struct mongory_matcher_explain_context {
16
- mongory_memory_pool *pool;
17
- int count;
18
- int total;
19
- char *prefix;
20
- } mongory_matcher_explain_context;
21
-
22
- /**
23
- * @brief Function pointer type for a matcher's explanation logic.
24
- *
25
- * @param matcher The matcher to explain.
26
- * @param ctx The context to use for the explanation.
27
- */
28
- typedef void (*mongory_matcher_explain_func)(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
29
-
30
- /**
31
- * @brief Explains a matcher.
32
- * @param matcher The matcher to explain.
33
- * @param ctx The context to use for the explanation.
34
- */
35
-
36
- char *mongory_matcher_title(struct mongory_matcher *matcher, mongory_memory_pool *pool);
37
-
38
- char *mongory_matcher_title_with_field(struct mongory_matcher *matcher, mongory_memory_pool *pool);
39
-
40
- void mongory_matcher_base_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
41
-
42
- void mongory_matcher_composite_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
43
-
44
- void mongory_matcher_traverse_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
45
-
46
- void mongory_matcher_field_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
47
-
48
- void mongory_matcher_literal_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
49
-
50
- #endif /* MONGORY_MATCHER_EXPLAINABLE_H */
@@ -1,55 +0,0 @@
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
- if (!mongory_matcher_leaf_traverse(matcher, ctx))
19
- return false;
20
- mongory_composite_matcher *composite = (mongory_composite_matcher *)matcher;
21
- mongory_array *children = composite->children;
22
- int total = (int)children->count;
23
- mongory_matcher_traverse_context child_ctx = {
24
- .pool = ctx->pool,
25
- .level = ctx->level + 1,
26
- .count = 0,
27
- .total = total,
28
- .acc = ctx->acc,
29
- .callback = ctx->callback,
30
- };
31
-
32
- for (int i = 0; i < total; i++) {
33
- mongory_matcher *child = (mongory_matcher *)children->get(children, i);
34
- if (!child->traverse(child, &child_ctx))
35
- return false;
36
- }
37
- return true;
38
- }
39
-
40
- bool mongory_matcher_literal_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
41
- if (!mongory_matcher_leaf_traverse(matcher, ctx))
42
- return false;
43
- mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
44
- mongory_matcher *next_matcher = literal->array_record_matcher ? literal->array_record_matcher : literal->delegate_matcher;
45
- mongory_matcher_traverse_context child_ctx = {
46
- .pool = ctx->pool,
47
- .level = ctx->level + 1,
48
- .count = 0,
49
- .total = 1,
50
- .acc = ctx->acc,
51
- .callback = ctx->callback,
52
- };
53
- return next_matcher->traverse(next_matcher, &child_ctx);
54
- }
55
- #endif /* MONGORY_MATCHER_TRAVERSABLE_C */
@@ -1,23 +0,0 @@
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 {
7
- mongory_memory_pool *pool;
8
- int level;
9
- int count;
10
- int total;
11
- void *acc;
12
- bool (*callback)(mongory_matcher *matcher, struct mongory_matcher_traverse_context *ctx);
13
- } mongory_matcher_traverse_context;
14
-
15
- typedef bool (*mongory_matcher_traverse_func)(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
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 */
data/mongory.gemspec DELETED
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/mongory/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'mongory'
7
- spec.version = Mongory::VERSION
8
- spec.authors = ['koten0224']
9
- spec.email = ['koten0224@gmail.com']
10
-
11
- spec.summary = 'MongoDB-like in-memory query DSL for Ruby'
12
- spec.description = 'A Mongo-like in-memory query DSL for Ruby'
13
- spec.homepage = 'https://mongoryhq.github.io/mongory-rb/'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 2.6.0'
16
-
17
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
- spec.metadata['rubygems_mfa_required'] = 'true'
19
- spec.metadata['homepage_uri'] = spec.homepage
20
- spec.metadata['source_code_uri'] = 'https://github.com/mongoryhq/mongory-rb'
21
- spec.metadata['changelog_uri'] = 'https://github.com/mongoryhq/mongory-rb/blob/main/CHANGELOG.md'
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (File.expand_path(f) == __FILE__) ||
28
- f.start_with?(*%w(bin/ test/ spec/ features/ .git .github appveyor Gemfile))
29
- end
30
- end
31
- spec.bindir = 'exe'
32
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
- spec.require_paths = ['lib']
34
-
35
- # C extension configuration
36
- spec.extensions = ['ext/mongory_ext/extconf.rb']
37
-
38
- # Add development dependencies for C extension
39
- spec.add_development_dependency 'rake-compiler', '~> 1.0'
40
-
41
- # Ensure submodule files are included
42
- spec.files += Dir['ext/mongory_ext/mongory-core/src/foundations/*.{c,h}']
43
- spec.files += Dir['ext/mongory_ext/mongory-core/src/matchers/*.{c,h}']
44
- spec.files += Dir['ext/mongory_ext/mongory-core/include/**/*.h']
45
- spec.files += ['ext/mongory_ext/mongory-core/LICENSE']
46
- end