mongory 0.8.2 → 0.9.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/docs/advanced_usage.md +7 -0
  4. data/docs/clang_bridge.md +6 -0
  5. data/ext/mongory_ext/extconf.rb +6 -1
  6. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +25 -0
  7. data/ext/mongory_ext/mongory-core/src/foundations/config.c +64 -27
  8. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +1 -0
  9. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +49 -0
  10. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +45 -0
  11. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +2 -5
  12. data/ext/mongory_ext/mongory-core/src/foundations/value.c +44 -7
  13. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +31 -10
  14. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +2 -0
  15. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +32 -13
  16. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +34 -13
  17. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +76 -15
  18. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +12 -0
  19. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +55 -17
  20. data/ext/mongory_ext/mongory_ext.c +35 -724
  21. data/ext/mongory_ext/mongory_ext_internal.h +75 -0
  22. data/ext/mongory_ext/rb_mongory_adapters.c +140 -0
  23. data/ext/mongory_ext/rb_mongory_cmatcher.c +386 -0
  24. data/ext/mongory_ext/rb_mongory_value.c +260 -0
  25. data/lib/generators/mongory/install/templates/initializer.rb.erb +5 -0
  26. data/lib/mongory/converters/abstract_converter.rb +6 -5
  27. data/lib/mongory/converters/condition_converter.rb +2 -2
  28. data/lib/mongory/matchers/abstract_matcher.rb +1 -1
  29. data/lib/mongory/matchers/abstract_multi_matcher.rb +2 -2
  30. data/lib/mongory/matchers/array_record_matcher.rb +23 -11
  31. data/lib/mongory/matchers/elem_match_matcher.rb +2 -0
  32. data/lib/mongory/matchers/eq_matcher.rb +4 -2
  33. data/lib/mongory/matchers/hash_condition_matcher.rb +23 -6
  34. data/lib/mongory/matchers/in_matcher.rb +17 -1
  35. data/lib/mongory/matchers/ne_matcher.rb +7 -6
  36. data/lib/mongory/matchers/nin_matcher.rb +2 -6
  37. data/lib/mongory/matchers/regex_matcher.rb +29 -0
  38. data/lib/mongory/matchers.rb +7 -4
  39. data/lib/mongory/version.rb +1 -1
  40. data/lib/mongory.rb +57 -5
  41. metadata +7 -2
data/lib/mongory.rb CHANGED
@@ -29,6 +29,8 @@ module Mongory
29
29
  class Error < StandardError; end
30
30
  class TypeError < Error; end
31
31
 
32
+ @c_extension_by_default = false
33
+
32
34
  # Yields Mongory for configuration and freezes key components.
33
35
  #
34
36
  # @example Configure converters
@@ -47,12 +49,21 @@ module Mongory
47
49
  # end
48
50
  #
49
51
  # @yieldparam self [Mongory]
50
- # @return [void]
52
+ # @return [self]
51
53
  def self.configure
52
54
  yield self
55
+ freeze
56
+ end
57
+
58
+ # Freezes Mongory configuration, converters, and matchers.
59
+ #
60
+ # @return [self]
61
+ def self.freeze
53
62
  data_converter.freeze
54
63
  condition_converter.freeze
64
+ @debugger = Utils::Debugger.instance
55
65
  Matchers.freeze
66
+ super
56
67
  end
57
68
 
58
69
  # Returns the data converter instance.
@@ -77,11 +88,25 @@ module Mongory
77
88
  end
78
89
 
79
90
  # Builds a new query over the given record set.
91
+ # Uses `CQueryBuilder` when `enable_c_extension_by_default!` is enabled and the C extension is available;
92
+ # otherwise uses `QueryBuilder`.
80
93
  #
81
94
  # @param records [Enumerable] any enumerable object (Array, AR::Relation, etc.)
82
- # @return [QueryBuilder] a new query builder
95
+ # @return [QueryBuilder, CQueryBuilder] a new query builder
83
96
  def self.build_query(records)
84
- QueryBuilder.new(records)
97
+ builder_class = c_extension_by_default? ? CQueryBuilder : QueryBuilder
98
+ builder_class.new(records)
99
+ end
100
+
101
+ # Builds a new matcher for the given condition.
102
+ # Uses `CMatcher` when `enable_c_extension_by_default!` is enabled and the C extension is available;
103
+ # otherwise uses `QueryMatcher`.
104
+ #
105
+ # @param condition [Hash] the query condition
106
+ # @return [QueryMatcher, CMatcher] a new matcher
107
+ def self.build_matcher(condition)
108
+ matcher_class = c_extension_by_default? ? CMatcher : QueryMatcher
109
+ matcher_class.new(condition)
85
110
  end
86
111
 
87
112
  # Registers a class to support `.mongory` query DSL.
@@ -103,15 +128,42 @@ module Mongory
103
128
  Matchers.enable_symbol_snippets!
104
129
  end
105
130
 
131
+ # Enables using the C extension (`CQueryBuilder`) by default when building queries
132
+ # via `Mongory.build_query` or `.mongory`.
133
+ #
134
+ # Automatically falls back to the pure Ruby `QueryBuilder` if the C extension is unavailable.
135
+ #
136
+ # @return [Boolean] true if C extension is available and enabled by default
137
+ def self.enable_c_extension_by_default!
138
+ @c_extension_by_default = !defined?(Mongory::CMatcher).nil?
139
+ end
140
+
141
+ singleton_class.alias_method :use_c_extension_by_default!, :enable_c_extension_by_default!
142
+
143
+ # Disables using the C extension by default, reverting `.mongory` and `Mongory.build_query`
144
+ # to the pure Ruby `QueryBuilder`.
145
+ #
146
+ # @return [void]
147
+ def self.disable_c_extension_by_default!
148
+ @c_extension_by_default = false
149
+ end
150
+
151
+ # Returns whether the C extension is used by default for queries.
152
+ #
153
+ # @return [Boolean]
154
+ def self.c_extension_by_default?
155
+ @c_extension_by_default == true && !defined?(Mongory::CMatcher).nil?
156
+ end
157
+
106
158
  # Adds a `#mongory` method to the target class via inclusion.
107
159
  #
108
160
  # Typically used internally by `Mongory.register(...)`.
109
161
  module ClassExtention
110
162
  # Returns a query builder scoped to `self`.
111
163
  #
112
- # @return [QueryBuilder]
164
+ # @return [QueryBuilder, CQueryBuilder]
113
165
  def mongory
114
- Mongory::QueryBuilder.new(self)
166
+ Mongory.build_query(self)
115
167
  end
116
168
  end
117
169
  end
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: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - koten0224
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-14 00:00:00.000000000 Z
11
+ date: 2026-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Mongo-like in-memory query DSL for Ruby
14
14
  email:
@@ -50,6 +50,7 @@ files:
50
50
  - ext/mongory_ext/mongory-core/src/foundations/config_private.h
51
51
  - ext/mongory_ext/mongory-core/src/foundations/error.c
52
52
  - ext/mongory_ext/mongory-core/src/foundations/memory_pool.c
53
+ - ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h
53
54
  - ext/mongory_ext/mongory-core/src/foundations/string_buffer.c
54
55
  - ext/mongory_ext/mongory-core/src/foundations/string_buffer.h
55
56
  - ext/mongory_ext/mongory-core/src/foundations/table.c
@@ -78,6 +79,10 @@ files:
78
79
  - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c
79
80
  - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h
80
81
  - ext/mongory_ext/mongory_ext.c
82
+ - ext/mongory_ext/mongory_ext_internal.h
83
+ - ext/mongory_ext/rb_mongory_adapters.c
84
+ - ext/mongory_ext/rb_mongory_cmatcher.c
85
+ - ext/mongory_ext/rb_mongory_value.c
81
86
  - lib/generators/mongory/install/install_generator.rb
82
87
  - lib/generators/mongory/install/templates/initializer.rb.erb
83
88
  - lib/generators/mongory/matcher/matcher_generator.rb