mongory 0.3.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -0
  3. data/README.md +37 -7
  4. data/examples/benchmark-rails.rb +52 -0
  5. data/examples/benchmark.rb +79 -18
  6. data/lib/generators/mongory/matcher/matcher_generator.rb +1 -1
  7. data/lib/mongory/converters/abstract_converter.rb +22 -32
  8. data/lib/mongory/converters/condition_converter.rb +7 -4
  9. data/lib/mongory/converters/data_converter.rb +18 -7
  10. data/lib/mongory/converters/key_converter.rb +43 -19
  11. data/lib/mongory/converters/value_converter.rb +24 -19
  12. data/lib/mongory/matchers/abstract_matcher.rb +94 -32
  13. data/lib/mongory/matchers/abstract_multi_matcher.rb +16 -45
  14. data/lib/mongory/matchers/and_matcher.rb +38 -10
  15. data/lib/mongory/matchers/array_record_matcher.rb +54 -28
  16. data/lib/mongory/matchers/elem_match_matcher.rb +13 -9
  17. data/lib/mongory/matchers/eq_matcher.rb +12 -7
  18. data/lib/mongory/matchers/every_matcher.rb +20 -9
  19. data/lib/mongory/matchers/exists_matcher.rb +15 -14
  20. data/lib/mongory/matchers/field_matcher.rb +58 -38
  21. data/lib/mongory/matchers/gt_matcher.rb +15 -7
  22. data/lib/mongory/matchers/gte_matcher.rb +15 -7
  23. data/lib/mongory/matchers/hash_condition_matcher.rb +47 -25
  24. data/lib/mongory/matchers/in_matcher.rb +12 -10
  25. data/lib/mongory/matchers/literal_matcher.rb +42 -48
  26. data/lib/mongory/matchers/lt_matcher.rb +15 -7
  27. data/lib/mongory/matchers/lte_matcher.rb +15 -7
  28. data/lib/mongory/matchers/ne_matcher.rb +12 -7
  29. data/lib/mongory/matchers/nin_matcher.rb +12 -9
  30. data/lib/mongory/matchers/not_matcher.rb +9 -5
  31. data/lib/mongory/matchers/or_matcher.rb +42 -13
  32. data/lib/mongory/matchers/present_matcher.rb +14 -15
  33. data/lib/mongory/matchers/regex_matcher.rb +37 -22
  34. data/lib/mongory/matchers.rb +0 -1
  35. data/lib/mongory/query_builder.rb +88 -26
  36. data/lib/mongory/query_matcher.rb +39 -12
  37. data/lib/mongory/query_operator.rb +1 -1
  38. data/lib/mongory/utils/context.rb +41 -0
  39. data/lib/mongory/utils/debugger.rb +6 -4
  40. data/lib/mongory/utils.rb +1 -0
  41. data/lib/mongory/version.rb +1 -1
  42. data/lib/mongory.rb +3 -3
  43. data/mongory.gemspec +3 -3
  44. metadata +9 -10
  45. data/lib/mongory/matchers/README.md +0 -57
  46. data/lib/mongory/matchers/abstract_operator_matcher.rb +0 -46
  47. data/lib/mongory-rb.rb +0 -3
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.3.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-19 00:00:00.000000000 Z
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,13 +26,13 @@ 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
32
33
  - lib/generators/mongory/matcher/matcher_generator.rb
33
34
  - lib/generators/mongory/matcher/templates/matcher.rb.erb
34
35
  - lib/generators/mongory/matcher/templates/matcher_spec.rb.erb
35
- - lib/mongory-rb.rb
36
36
  - lib/mongory.rb
37
37
  - lib/mongory/converters.rb
38
38
  - lib/mongory/converters/abstract_converter.rb
@@ -41,10 +41,8 @@ files:
41
41
  - lib/mongory/converters/key_converter.rb
42
42
  - lib/mongory/converters/value_converter.rb
43
43
  - lib/mongory/matchers.rb
44
- - lib/mongory/matchers/README.md
45
44
  - lib/mongory/matchers/abstract_matcher.rb
46
45
  - lib/mongory/matchers/abstract_multi_matcher.rb
47
- - lib/mongory/matchers/abstract_operator_matcher.rb
48
46
  - lib/mongory/matchers/and_matcher.rb
49
47
  - lib/mongory/matchers/array_record_matcher.rb
50
48
  - lib/mongory/matchers/elem_match_matcher.rb
@@ -71,21 +69,22 @@ files:
71
69
  - lib/mongory/query_operator.rb
72
70
  - lib/mongory/rails.rb
73
71
  - lib/mongory/utils.rb
72
+ - lib/mongory/utils/context.rb
74
73
  - lib/mongory/utils/debugger.rb
75
74
  - lib/mongory/utils/rails_patch.rb
76
75
  - lib/mongory/utils/singleton_builder.rb
77
76
  - lib/mongory/version.rb
78
77
  - mongory.gemspec
79
78
  - sig/mongory.rbs
80
- homepage: https://koten0224.github.io/mongory-rb/
79
+ homepage: https://mongoryhq.github.io/mongory-rb/
81
80
  licenses:
82
81
  - MIT
83
82
  metadata:
84
83
  allowed_push_host: https://rubygems.org
85
84
  rubygems_mfa_required: 'true'
86
- homepage_uri: https://koten0224.github.io/mongory-rb/
87
- source_code_uri: https://github.com/koten0224/mongory-rb
88
- changelog_uri: https://github.com/koten0224/mongory-rb/blob/main/CHANGELOG.md
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
89
88
  post_install_message:
90
89
  rdoc_options: []
91
90
  require_paths:
@@ -101,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
100
  - !ruby/object:Gem::Version
102
101
  version: '0'
103
102
  requirements: []
104
- rubygems_version: 3.1.6
103
+ rubygems_version: 3.0.8
105
104
  signing_key:
106
105
  specification_version: 4
107
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
data/lib/mongory-rb.rb DELETED
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'mongory'