mongory 0.8.1-aarch64-linux → 0.9.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/README.md +12 -0
  4. data/docs/advanced_usage.md +7 -0
  5. data/docs/clang_bridge.md +6 -0
  6. data/ext/mongory_ext/extconf.rb +6 -1
  7. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +25 -0
  8. data/ext/mongory_ext/mongory-core/src/foundations/array.c +22 -15
  9. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +1 -0
  10. data/ext/mongory_ext/mongory-core/src/foundations/config.c +64 -27
  11. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +1 -0
  12. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +49 -0
  13. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +45 -0
  14. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -2
  15. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -6
  16. data/ext/mongory_ext/mongory-core/src/foundations/table.c +9 -10
  17. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +21 -14
  18. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +2 -2
  19. data/ext/mongory_ext/mongory-core/src/foundations/value.c +54 -9
  20. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +31 -10
  21. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +2 -0
  22. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +2 -0
  23. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +32 -13
  24. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +34 -13
  25. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +16 -3
  26. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +76 -15
  27. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +12 -0
  28. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +57 -15
  29. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +43 -7
  30. data/ext/mongory_ext/mongory_ext.c +36 -687
  31. data/ext/mongory_ext/mongory_ext_internal.h +75 -0
  32. data/ext/mongory_ext/rb_mongory_adapters.c +140 -0
  33. data/ext/mongory_ext/rb_mongory_cmatcher.c +386 -0
  34. data/ext/mongory_ext/rb_mongory_value.c +260 -0
  35. data/lib/core/2.6/mongory_ext.so +0 -0
  36. data/lib/core/2.7/mongory_ext.so +0 -0
  37. data/lib/core/3.0/mongory_ext.so +0 -0
  38. data/lib/core/3.1/mongory_ext.so +0 -0
  39. data/lib/core/3.2/mongory_ext.so +0 -0
  40. data/lib/core/3.3/mongory_ext.so +0 -0
  41. data/lib/core/3.4/mongory_ext.so +0 -0
  42. data/lib/core/4.0/mongory_ext.so +0 -0
  43. data/lib/generators/mongory/install/templates/initializer.rb.erb +5 -0
  44. data/lib/mongory/converters/abstract_converter.rb +6 -5
  45. data/lib/mongory/converters/condition_converter.rb +2 -2
  46. data/lib/mongory/converters/key_converter.rb +1 -1
  47. data/lib/mongory/matchers/abstract_matcher.rb +1 -1
  48. data/lib/mongory/matchers/abstract_multi_matcher.rb +2 -2
  49. data/lib/mongory/matchers/array_record_matcher.rb +23 -11
  50. data/lib/mongory/matchers/elem_match_matcher.rb +2 -0
  51. data/lib/mongory/matchers/eq_matcher.rb +4 -2
  52. data/lib/mongory/matchers/field_matcher.rb +16 -3
  53. data/lib/mongory/matchers/hash_condition_matcher.rb +23 -6
  54. data/lib/mongory/matchers/in_matcher.rb +17 -1
  55. data/lib/mongory/matchers/ne_matcher.rb +7 -6
  56. data/lib/mongory/matchers/nin_matcher.rb +2 -6
  57. data/lib/mongory/matchers/regex_matcher.rb +29 -0
  58. data/lib/mongory/matchers.rb +7 -4
  59. data/lib/mongory/version.rb +1 -1
  60. data/lib/mongory.rb +57 -5
  61. metadata +8 -2
@@ -31,6 +31,35 @@ module Mongory
31
31
  #
32
32
  # @see AbstractMatcher
33
33
  class RegexMatcher < AbstractMatcher
34
+ # MongoDB `$options` flags mapped to Ruby. Ruby's `^`/`$` always match at
35
+ # line boundaries, so `m` needs no flag; Ruby's MULTILINE is MongoDB's `s`.
36
+ OPTION_FLAGS = {
37
+ 'i' => Regexp::IGNORECASE,
38
+ 'm' => 0,
39
+ 's' => Regexp::MULTILINE
40
+ }.freeze
41
+
42
+ # Compiles a `$regex` pattern string with MongoDB `$options` flags.
43
+ #
44
+ # @param pattern [String, Regexp, Object] the `$regex` value
45
+ # @param options [Object] the `$options` value
46
+ # @return [Regexp, Object] the compiled Regexp, or a non-string pattern
47
+ # unchanged so that check_validity! reports it
48
+ # @raise [TypeError] if options is invalid or pattern is already a Regexp
49
+ def self.apply_options(pattern, options)
50
+ raise TypeError, '$options needs a string' unless options.is_a?(String)
51
+
52
+ flags = options.each_char.reduce(0) do |result, char|
53
+ raise TypeError, "unsupported $options flag #{char.inspect}" unless OPTION_FLAGS.key?(char)
54
+
55
+ result | OPTION_FLAGS[char]
56
+ end
57
+ raise TypeError, '$options cannot modify a Regexp' if pattern.is_a?(Regexp)
58
+ return pattern unless pattern.is_a?(String)
59
+
60
+ Regexp.new(pattern, flags)
61
+ end
62
+
34
63
  # Initializes the matcher with a regex pattern.
35
64
  # Converts string patterns to Regexp objects.
36
65
  #
@@ -16,6 +16,7 @@ module Mongory
16
16
  module Matchers
17
17
  @operator_mapping = {}
18
18
  @registries = []
19
+ @enable_symbol_snippets = false
19
20
 
20
21
  # Registers a matcher class for a given operator and method symbol.
21
22
  #
@@ -26,11 +27,11 @@ module Mongory
26
27
  # @raise [ArgumentError] if validations fail
27
28
  def self.register(method_sym, operator, klass)
28
29
  Validator.validate_method(method_sym)
29
- Validator.validate_operator(operator)
30
+ Validator.validate_operator(operator, klass)
30
31
  Validator.validate_class(klass)
31
32
 
32
33
  @operator_mapping[operator] = klass
33
- registry = Registry.new(method_sym, operator)
34
+ registry = Registry.new(method_sym, operator).freeze
34
35
  @registries << registry
35
36
  return unless @enable_symbol_snippets
36
37
 
@@ -62,9 +63,10 @@ module Mongory
62
63
  end
63
64
 
64
65
  def self.freeze
65
- super
66
+ @registries.each(&:freeze)
66
67
  @operator_mapping.freeze
67
68
  @registries.freeze
69
+ super
68
70
  end
69
71
 
70
72
  # @private
@@ -85,9 +87,10 @@ module Mongory
85
87
  # Warns on duplicate registration.
86
88
  #
87
89
  # @param operator [String]
90
+ # @param klass [Class, nil]
88
91
  # @return [void]
89
92
  # @raise [Mongory::TypeError] if operator format is invalid
90
- def self.validate_operator(operator)
93
+ def self.validate_operator(operator, klass = nil)
91
94
  if Matchers.lookup(operator)
92
95
  warn "Duplicate operator registration: #{operator} (#{Matchers.lookup(operator)} vs #{klass})"
93
96
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mongory
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.0'
5
5
  end
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.1
4
+ version: 0.9.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: 2025-08-30 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Mongo-like in-memory query DSL for Ruby
14
14
  email:
@@ -49,6 +49,7 @@ files:
49
49
  - ext/mongory_ext/mongory-core/src/foundations/config_private.h
50
50
  - ext/mongory_ext/mongory-core/src/foundations/error.c
51
51
  - ext/mongory_ext/mongory-core/src/foundations/memory_pool.c
52
+ - ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h
52
53
  - ext/mongory_ext/mongory-core/src/foundations/string_buffer.c
53
54
  - ext/mongory_ext/mongory-core/src/foundations/string_buffer.h
54
55
  - ext/mongory_ext/mongory-core/src/foundations/table.c
@@ -77,6 +78,10 @@ files:
77
78
  - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c
78
79
  - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h
79
80
  - ext/mongory_ext/mongory_ext.c
81
+ - ext/mongory_ext/mongory_ext_internal.h
82
+ - ext/mongory_ext/rb_mongory_adapters.c
83
+ - ext/mongory_ext/rb_mongory_cmatcher.c
84
+ - ext/mongory_ext/rb_mongory_value.c
80
85
  - lib/core/2.6/mongory_ext.so
81
86
  - lib/core/2.7/mongory_ext.so
82
87
  - lib/core/3.0/mongory_ext.so
@@ -84,6 +89,7 @@ files:
84
89
  - lib/core/3.2/mongory_ext.so
85
90
  - lib/core/3.3/mongory_ext.so
86
91
  - lib/core/3.4/mongory_ext.so
92
+ - lib/core/4.0/mongory_ext.so
87
93
  - lib/generators/mongory/install/install_generator.rb
88
94
  - lib/generators/mongory/install/templates/initializer.rb.erb
89
95
  - lib/generators/mongory/matcher/matcher_generator.rb