mongory 0.8.1 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/README.md +12 -0
- data/docs/advanced_usage.md +7 -0
- data/docs/clang_bridge.md +6 -0
- data/ext/mongory_ext/extconf.rb +6 -1
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +25 -0
- data/ext/mongory_ext/mongory-core/src/foundations/array.c +22 -15
- data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +1 -0
- data/ext/mongory_ext/mongory-core/src/foundations/config.c +64 -27
- data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +1 -0
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +49 -0
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +45 -0
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -2
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -6
- data/ext/mongory_ext/mongory-core/src/foundations/table.c +9 -10
- data/ext/mongory_ext/mongory-core/src/foundations/utils.c +21 -14
- data/ext/mongory_ext/mongory-core/src/foundations/utils.h +2 -2
- data/ext/mongory_ext/mongory-core/src/foundations/value.c +54 -9
- data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +31 -10
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +2 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +2 -0
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +32 -13
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +34 -13
- data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +16 -3
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +76 -15
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +12 -0
- data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +57 -15
- data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +43 -7
- data/ext/mongory_ext/mongory_ext.c +36 -687
- data/ext/mongory_ext/mongory_ext_internal.h +75 -0
- data/ext/mongory_ext/rb_mongory_adapters.c +140 -0
- data/ext/mongory_ext/rb_mongory_cmatcher.c +386 -0
- data/ext/mongory_ext/rb_mongory_value.c +260 -0
- data/lib/generators/mongory/install/templates/initializer.rb.erb +5 -0
- data/lib/mongory/converters/abstract_converter.rb +6 -5
- data/lib/mongory/converters/condition_converter.rb +2 -2
- data/lib/mongory/converters/key_converter.rb +1 -1
- data/lib/mongory/matchers/abstract_matcher.rb +1 -1
- data/lib/mongory/matchers/abstract_multi_matcher.rb +2 -2
- data/lib/mongory/matchers/array_record_matcher.rb +23 -11
- data/lib/mongory/matchers/elem_match_matcher.rb +2 -0
- data/lib/mongory/matchers/eq_matcher.rb +4 -2
- data/lib/mongory/matchers/field_matcher.rb +16 -3
- data/lib/mongory/matchers/hash_condition_matcher.rb +23 -6
- data/lib/mongory/matchers/in_matcher.rb +17 -1
- data/lib/mongory/matchers/ne_matcher.rb +7 -6
- data/lib/mongory/matchers/nin_matcher.rb +2 -6
- data/lib/mongory/matchers/regex_matcher.rb +29 -0
- data/lib/mongory/matchers.rb +7 -4
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +57 -5
- metadata +7 -2
data/lib/mongory/matchers.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/mongory/version.rb
CHANGED
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 [
|
|
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
|
|
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
|
|
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.
|
|
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:
|
|
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
|