mongory 0.4.0 → 0.6.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 +44 -0
- data/README.md +37 -7
- data/examples/benchmark-rails.rb +52 -0
- data/examples/benchmark.rb +79 -18
- data/lib/generators/mongory/matcher/matcher_generator.rb +1 -1
- data/lib/mongory/converters/abstract_converter.rb +22 -32
- data/lib/mongory/converters/condition_converter.rb +7 -4
- data/lib/mongory/converters/data_converter.rb +18 -7
- data/lib/mongory/converters/key_converter.rb +43 -19
- data/lib/mongory/converters/value_converter.rb +24 -19
- data/lib/mongory/matchers/abstract_matcher.rb +94 -32
- data/lib/mongory/matchers/abstract_multi_matcher.rb +16 -45
- data/lib/mongory/matchers/and_matcher.rb +38 -10
- data/lib/mongory/matchers/array_record_matcher.rb +54 -28
- data/lib/mongory/matchers/elem_match_matcher.rb +13 -9
- data/lib/mongory/matchers/eq_matcher.rb +12 -7
- data/lib/mongory/matchers/every_matcher.rb +20 -9
- data/lib/mongory/matchers/exists_matcher.rb +15 -14
- data/lib/mongory/matchers/field_matcher.rb +58 -38
- data/lib/mongory/matchers/gt_matcher.rb +15 -7
- data/lib/mongory/matchers/gte_matcher.rb +15 -7
- data/lib/mongory/matchers/hash_condition_matcher.rb +47 -25
- data/lib/mongory/matchers/in_matcher.rb +12 -10
- data/lib/mongory/matchers/literal_matcher.rb +42 -48
- data/lib/mongory/matchers/lt_matcher.rb +15 -7
- data/lib/mongory/matchers/lte_matcher.rb +15 -7
- data/lib/mongory/matchers/ne_matcher.rb +12 -7
- data/lib/mongory/matchers/nin_matcher.rb +12 -9
- data/lib/mongory/matchers/not_matcher.rb +9 -5
- data/lib/mongory/matchers/or_matcher.rb +42 -13
- data/lib/mongory/matchers/present_matcher.rb +14 -15
- data/lib/mongory/matchers/regex_matcher.rb +37 -22
- data/lib/mongory/matchers.rb +0 -1
- data/lib/mongory/query_builder.rb +88 -26
- data/lib/mongory/query_matcher.rb +39 -12
- data/lib/mongory/query_operator.rb +1 -1
- data/lib/mongory/utils/context.rb +41 -0
- data/lib/mongory/utils/debugger.rb +6 -4
- data/lib/mongory/utils.rb +1 -0
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +3 -3
- data/mongory.gemspec +3 -3
- metadata +9 -9
- data/lib/mongory/matchers/README.md +0 -57
- data/lib/mongory/matchers/abstract_operator_matcher.rb +0 -46
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- koten0224
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Mongo-like in-memory query DSL for Ruby
|
14
14
|
email:
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- README.md
|
27
27
|
- Rakefile
|
28
28
|
- examples/README.md
|
29
|
+
- examples/benchmark-rails.rb
|
29
30
|
- examples/benchmark.rb
|
30
31
|
- lib/generators/mongory/install/install_generator.rb
|
31
32
|
- lib/generators/mongory/install/templates/initializer.rb.erb
|
@@ -40,10 +41,8 @@ files:
|
|
40
41
|
- lib/mongory/converters/key_converter.rb
|
41
42
|
- lib/mongory/converters/value_converter.rb
|
42
43
|
- lib/mongory/matchers.rb
|
43
|
-
- lib/mongory/matchers/README.md
|
44
44
|
- lib/mongory/matchers/abstract_matcher.rb
|
45
45
|
- lib/mongory/matchers/abstract_multi_matcher.rb
|
46
|
-
- lib/mongory/matchers/abstract_operator_matcher.rb
|
47
46
|
- lib/mongory/matchers/and_matcher.rb
|
48
47
|
- lib/mongory/matchers/array_record_matcher.rb
|
49
48
|
- lib/mongory/matchers/elem_match_matcher.rb
|
@@ -70,21 +69,22 @@ files:
|
|
70
69
|
- lib/mongory/query_operator.rb
|
71
70
|
- lib/mongory/rails.rb
|
72
71
|
- lib/mongory/utils.rb
|
72
|
+
- lib/mongory/utils/context.rb
|
73
73
|
- lib/mongory/utils/debugger.rb
|
74
74
|
- lib/mongory/utils/rails_patch.rb
|
75
75
|
- lib/mongory/utils/singleton_builder.rb
|
76
76
|
- lib/mongory/version.rb
|
77
77
|
- mongory.gemspec
|
78
78
|
- sig/mongory.rbs
|
79
|
-
homepage: https://
|
79
|
+
homepage: https://mongoryhq.github.io/mongory-rb/
|
80
80
|
licenses:
|
81
81
|
- MIT
|
82
82
|
metadata:
|
83
83
|
allowed_push_host: https://rubygems.org
|
84
84
|
rubygems_mfa_required: 'true'
|
85
|
-
homepage_uri: https://
|
86
|
-
source_code_uri: https://github.com/
|
87
|
-
changelog_uri: https://github.com/
|
85
|
+
homepage_uri: https://mongoryhq.github.io/mongory-rb/
|
86
|
+
source_code_uri: https://github.com/mongoryhq/mongory-rb
|
87
|
+
changelog_uri: https://github.com/mongoryhq/mongory-rb/blob/main/CHANGELOG.md
|
88
88
|
post_install_message:
|
89
89
|
rdoc_options: []
|
90
90
|
require_paths:
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.0.8
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: MongoDB-like in-memory query DSL for Ruby
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# Matcher classes inheritance diagram
|
2
|
-
|
3
|
-
```mermaid
|
4
|
-
---
|
5
|
-
config:
|
6
|
-
theme: neutral
|
7
|
-
look: classic
|
8
|
-
---
|
9
|
-
|
10
|
-
graph TD
|
11
|
-
%% style blocks
|
12
|
-
classDef abstract fill:#ddd,stroke:#333,stroke-width:1px,color:#000;
|
13
|
-
classDef main fill:#cce5ff,stroke:#339,stroke-width:1px;
|
14
|
-
classDef multi fill:#d4edda,stroke:#282,stroke-width:1px;
|
15
|
-
classDef operator fill:#fff3cd,stroke:#aa8800,stroke-width:1px;
|
16
|
-
classDef leaf fill:#f8f9fa,stroke:#999,stroke-width:1px;
|
17
|
-
|
18
|
-
%% Abstract base classes
|
19
|
-
A[AbstractMatcher]
|
20
|
-
C[AbstractMultiMatcher]
|
21
|
-
D[AbstractOperatorMatcher]
|
22
|
-
|
23
|
-
subgraph MultipleConditions
|
24
|
-
F[HashConditionMatcher]
|
25
|
-
I[AndMatcher]
|
26
|
-
J[OrMatcher]
|
27
|
-
W[ArrayRecordMatcher]
|
28
|
-
end
|
29
|
-
|
30
|
-
subgraph SimpleCompare
|
31
|
-
E[EqMatcher]
|
32
|
-
K[RegexMatcher]
|
33
|
-
L[PresentMatcher]
|
34
|
-
M[ExistsMatcher]
|
35
|
-
O[NeMatcher]
|
36
|
-
Q[GtMatcher]
|
37
|
-
R[GteMatcher]
|
38
|
-
S[LtMatcher]
|
39
|
-
T[LteMatcher]
|
40
|
-
end
|
41
|
-
|
42
|
-
A --> B[LiteralMatcher]
|
43
|
-
A --> U[InMatcher]
|
44
|
-
A --> V[NinMatcher]
|
45
|
-
A --> C --> MultipleConditions
|
46
|
-
A --> D --> SimpleCompare
|
47
|
-
B --> G[FieldMatcher]
|
48
|
-
B --> H[ElemMatchMatcher]
|
49
|
-
B --> N[NotMatcher]
|
50
|
-
|
51
|
-
%% Apply classes
|
52
|
-
class A,C,D abstract;
|
53
|
-
class B main;
|
54
|
-
class F,I,J,W multi;
|
55
|
-
class E,K,L,M,O,Q,R,S,T operator;
|
56
|
-
class G,U,V,H,N leaf;
|
57
|
-
```
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mongory
|
4
|
-
module Matchers
|
5
|
-
# AbstractOperatorMatcher is a base class for matchers that apply a binary
|
6
|
-
# operator (e.g., `==`, `<`, `>` etc.) between the record and the condition.
|
7
|
-
#
|
8
|
-
# This class assumes that the match logic consists of:
|
9
|
-
# preprocess(record).send(operator, condition)
|
10
|
-
# and provides a fallback behavior for invalid comparisons.
|
11
|
-
#
|
12
|
-
# Subclasses must implement `#operator` and may override `#preprocess`
|
13
|
-
# to normalize or cast the record before comparison.
|
14
|
-
#
|
15
|
-
# @abstract
|
16
|
-
# @see AbstractMatcher
|
17
|
-
class AbstractOperatorMatcher < AbstractMatcher
|
18
|
-
# A list of Boolean values used for type guarding in some subclasses.
|
19
|
-
BOOLEAN_VALUES = [true, false].freeze
|
20
|
-
|
21
|
-
# Applies the binary operator to the preprocessed record and condition.
|
22
|
-
# If an error is raised (e.g., undefined comparison), the match fails.
|
23
|
-
#
|
24
|
-
# @param record [Object] the input record to test
|
25
|
-
# @return [Boolean] the result of record <operator> condition
|
26
|
-
def match(record)
|
27
|
-
preprocess(record).send(operator, @condition)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Hook for subclasses to transform the record before comparison.
|
31
|
-
# Default behavior normalizes KEY_NOT_FOUND to nil.
|
32
|
-
#
|
33
|
-
# @param record [Object] the raw record value
|
34
|
-
# @return [Object] the transformed value
|
35
|
-
def preprocess(record)
|
36
|
-
normalize(record)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Returns the Ruby operator symbol to be used in comparison.
|
40
|
-
# Must be implemented by subclasses (e.g., :==, :<, :>=)
|
41
|
-
#
|
42
|
-
# @return [Symbol] the comparison operator
|
43
|
-
def operator; end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|