mongory 0.6.2 → 0.7.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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +42 -0
  4. data/README.md +82 -176
  5. data/Rakefile +77 -0
  6. data/SUBMODULE_INTEGRATION.md +325 -0
  7. data/docs/advanced_usage.md +40 -0
  8. data/docs/clang_bridge.md +69 -0
  9. data/docs/field_names.md +30 -0
  10. data/docs/migration.md +30 -0
  11. data/docs/performance.md +61 -0
  12. data/examples/benchmark.rb +98 -19
  13. data/ext/mongory_ext/extconf.rb +91 -0
  14. data/ext/mongory_ext/mongory-core/LICENSE +3 -0
  15. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +105 -0
  16. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +206 -0
  17. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +82 -0
  18. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +95 -0
  19. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +108 -0
  20. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +175 -0
  21. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +76 -0
  22. data/ext/mongory_ext/mongory-core/include/mongory-core.h +12 -0
  23. data/ext/mongory_ext/mongory-core/src/foundations/array.c +246 -0
  24. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +18 -0
  25. data/ext/mongory_ext/mongory-core/src/foundations/config.c +406 -0
  26. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +30 -0
  27. data/ext/mongory_ext/mongory-core/src/foundations/error.c +30 -0
  28. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +298 -0
  29. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +65 -0
  30. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +49 -0
  31. data/ext/mongory_ext/mongory-core/src/foundations/table.c +458 -0
  32. data/ext/mongory_ext/mongory-core/src/foundations/value.c +459 -0
  33. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +309 -0
  34. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h +47 -0
  35. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +161 -0
  36. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +115 -0
  37. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +210 -0
  38. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +83 -0
  39. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +539 -0
  40. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +125 -0
  41. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +144 -0
  42. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.h +48 -0
  43. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +121 -0
  44. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +46 -0
  45. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +199 -0
  46. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +46 -0
  47. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +334 -0
  48. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h +97 -0
  49. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +196 -0
  50. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +107 -0
  51. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +50 -0
  52. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +55 -0
  53. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +23 -0
  54. data/ext/mongory_ext/mongory_ext.c +635 -0
  55. data/lib/mongory/c_query_builder.rb +44 -0
  56. data/lib/mongory/converters/converted.rb +2 -2
  57. data/lib/mongory/matchers/abstract_matcher.rb +4 -0
  58. data/lib/mongory/matchers/abstract_multi_matcher.rb +44 -0
  59. data/lib/mongory/matchers/and_matcher.rb +2 -23
  60. data/lib/mongory/matchers/array_record_matcher.rb +2 -23
  61. data/lib/mongory/matchers/elem_match_matcher.rb +4 -0
  62. data/lib/mongory/matchers/eq_matcher.rb +4 -0
  63. data/lib/mongory/matchers/every_matcher.rb +4 -0
  64. data/lib/mongory/matchers/exists_matcher.rb +4 -0
  65. data/lib/mongory/matchers/field_matcher.rb +4 -0
  66. data/lib/mongory/matchers/gt_matcher.rb +4 -0
  67. data/lib/mongory/matchers/gte_matcher.rb +4 -0
  68. data/lib/mongory/matchers/hash_condition_matcher.rb +2 -23
  69. data/lib/mongory/matchers/in_matcher.rb +13 -4
  70. data/lib/mongory/matchers/literal_matcher.rb +4 -0
  71. data/lib/mongory/matchers/lt_matcher.rb +4 -0
  72. data/lib/mongory/matchers/lte_matcher.rb +4 -0
  73. data/lib/mongory/matchers/ne_matcher.rb +4 -0
  74. data/lib/mongory/matchers/nin_matcher.rb +14 -5
  75. data/lib/mongory/matchers/not_matcher.rb +4 -0
  76. data/lib/mongory/matchers/or_matcher.rb +2 -23
  77. data/lib/mongory/matchers/present_matcher.rb +4 -0
  78. data/lib/mongory/matchers/regex_matcher.rb +4 -0
  79. data/lib/mongory/matchers/size_matcher.rb +4 -0
  80. data/lib/mongory/query_builder.rb +8 -0
  81. data/lib/mongory/utils/context.rb +7 -0
  82. data/lib/mongory/utils.rb +1 -1
  83. data/lib/mongory/version.rb +1 -1
  84. data/lib/mongory.rb +7 -0
  85. data/mongory.gemspec +10 -4
  86. data/scripts/build_with_core.sh +292 -0
  87. metadata +70 -5
@@ -0,0 +1,292 @@
1
+ #!/bin/bash
2
+
3
+ # Build script for mongory-rb with mongory-core submodule
4
+ # This script handles submodule initialization, dependency checking, and C extension compilation
5
+
6
+ set -e # Exit on any error
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
10
+ CORE_DIR="$PROJECT_ROOT/ext/mongory_ext/mongory-core"
11
+
12
+ # Colors for output
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ BLUE='\033[0;34m'
17
+ NC='\033[0m' # No Color
18
+
19
+ # Function to print colored output
20
+ log() {
21
+ local color=$1
22
+ shift
23
+ echo -e "${color}$*${NC}"
24
+ }
25
+
26
+ # Function to check if command exists
27
+ command_exists() {
28
+ command -v "$1" >/dev/null 2>&1
29
+ }
30
+
31
+ # Function to check system dependencies
32
+ check_dependencies() {
33
+ log $BLUE "🔍 Checking system dependencies..."
34
+
35
+ local missing_deps=()
36
+
37
+ # Check for required tools
38
+ if ! command_exists git; then
39
+ missing_deps+=("git")
40
+ fi
41
+
42
+ if ! command_exists make; then
43
+ missing_deps+=("make")
44
+ fi
45
+
46
+ if ! command_exists gcc && ! command_exists clang; then
47
+ missing_deps+=("gcc or clang")
48
+ fi
49
+
50
+ # Check for pkg-config (optional)
51
+ if ! command_exists pkg-config; then
52
+ missing_deps+=("pkg-config")
53
+ fi
54
+
55
+ if [ ${#missing_deps[@]} -gt 0 ]; then
56
+ log $RED "❌ Missing dependencies: ${missing_deps[*]}"
57
+ log $YELLOW "Please install the missing dependencies:"
58
+
59
+ if [[ "$OSTYPE" == "darwin"* ]]; then
60
+ log $BLUE " macOS (Homebrew): brew install ${missing_deps[*]// /}"
61
+ elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
62
+ if command_exists apt; then
63
+ log $BLUE " Ubuntu/Debian: sudo apt update && sudo apt install build-essential pkg-config"
64
+ elif command_exists yum; then
65
+ log $BLUE " CentOS/RHEL: sudo yum install gcc make pkg-config"
66
+ elif command_exists dnf; then
67
+ log $BLUE " Fedora: sudo dnf install gcc make pkg-config"
68
+ fi
69
+ fi
70
+
71
+ exit 1
72
+ fi
73
+
74
+ log $GREEN "✅ All dependencies found"
75
+ }
76
+
77
+ # Function to initialize/update submodules
78
+ init_submodules() {
79
+ log $BLUE "📥 Initializing/updating submodules..."
80
+
81
+ cd "$PROJECT_ROOT"
82
+
83
+ if [ ! -d "$CORE_DIR" ] || [ ! "$(ls -A "$CORE_DIR")" ]; then
84
+ log $YELLOW "Submodule not initialized, initializing now..."
85
+ git submodule update --init --recursive
86
+ else
87
+ log $YELLOW "Updating existing submodule..."
88
+ git submodule update --recursive
89
+ fi
90
+
91
+ if [ ! -f "$CORE_DIR/README.md" ]; then
92
+ log $RED "❌ Failed to initialize mongory-core submodule"
93
+ exit 1
94
+ fi
95
+
96
+ log $GREEN "✅ Submodule initialized/updated successfully"
97
+ }
98
+
99
+ # Function to build mongory-core if needed
100
+ build_core() {
101
+ # mongory-rb 直接由 extconf.rb 編譯 mongory-core 的源碼,不需要獨立建置靜態庫
102
+ # 同時避免觸發 mongory-core 的 CMake(其需要 cJSON 僅用於測試)
103
+ log $YELLOW "Skipping mongory-core standalone build (not required for mongory-rb)"
104
+ }
105
+
106
+ # Function to build the Ruby C extension
107
+ build_extension() {
108
+ log $BLUE "🔨 Building Ruby C extension..."
109
+
110
+ cd "$PROJECT_ROOT"
111
+
112
+ # Clean previous builds
113
+ if [ -d "ext/mongory_ext/Makefile" ]; then
114
+ cd ext/mongory_ext
115
+ make clean 2>/dev/null || true
116
+ cd "$PROJECT_ROOT"
117
+ fi
118
+
119
+ # Build the extension
120
+ cd ext/mongory_ext
121
+
122
+ # Set DEBUG flag if requested
123
+ if [[ "$1" == "--debug" ]]; then
124
+ export DEBUG=1
125
+ log $YELLOW "Building in debug mode..."
126
+ fi
127
+
128
+ ruby extconf.rb
129
+ make
130
+
131
+ if [ $? -eq 0 ]; then
132
+ log $GREEN "✅ C extension built successfully"
133
+ else
134
+ log $RED "❌ Failed to build C extension"
135
+ exit 1
136
+ fi
137
+
138
+ cd "$PROJECT_ROOT"
139
+ }
140
+
141
+ # Function to run tests
142
+ run_tests() {
143
+ log $BLUE "🧪 Running tests..."
144
+
145
+ cd "$PROJECT_ROOT"
146
+
147
+ # Run Ruby tests
148
+ if command_exists bundle; then
149
+ bundle exec rspec
150
+ else
151
+ rspec
152
+ fi
153
+
154
+ if [ $? -eq 0 ]; then
155
+ log $GREEN "✅ All tests passed"
156
+ else
157
+ log $RED "❌ Some tests failed"
158
+ exit 1
159
+ fi
160
+ }
161
+
162
+ # Function to clean build artifacts
163
+ clean() {
164
+ log $BLUE "🧹 Cleaning build artifacts..."
165
+
166
+ cd "$PROJECT_ROOT"
167
+
168
+ # Clean C extension
169
+ if [ -d "ext/mongory_ext" ]; then
170
+ cd ext/mongory_ext
171
+ make clean 2>/dev/null || true
172
+ rm -f Makefile *.o foundations/*.o matchers/*.o mongory_ext.so
173
+ cd "$PROJECT_ROOT"
174
+ fi
175
+
176
+ # Clean mongory-core build
177
+ if [ -d "$CORE_DIR/build" ]; then
178
+ rm -rf "$CORE_DIR/build"
179
+ fi
180
+
181
+ log $GREEN "✅ Cleaned build artifacts"
182
+ }
183
+
184
+ # Function to display help
185
+ show_help() {
186
+ cat << EOF
187
+ Usage: $0 [OPTIONS]
188
+
189
+ Build script for mongory-rb with mongory-core submodule integration.
190
+
191
+ OPTIONS:
192
+ --help Show this help message
193
+ --clean Clean build artifacts and exit
194
+ --debug Build in debug mode
195
+ --no-deps Skip dependency checking
196
+ --no-tests Skip running tests
197
+ --force-rebuild Force rebuild of everything
198
+
199
+ EXAMPLES:
200
+ $0 # Normal build
201
+ $0 --debug # Debug build
202
+ $0 --clean # Clean only
203
+ $0 --no-tests # Build without running tests
204
+
205
+ EOF
206
+ }
207
+
208
+ # Main execution flow
209
+ main() {
210
+ local clean_only=false
211
+ local skip_deps=false
212
+ local skip_tests=false
213
+ local force_rebuild=false
214
+ local debug_mode=false
215
+
216
+ # Parse command line arguments
217
+ while [[ $# -gt 0 ]]; do
218
+ case $1 in
219
+ --help)
220
+ show_help
221
+ exit 0
222
+ ;;
223
+ --clean)
224
+ clean_only=true
225
+ shift
226
+ ;;
227
+ --debug)
228
+ debug_mode=true
229
+ shift
230
+ ;;
231
+ --no-deps)
232
+ skip_deps=true
233
+ shift
234
+ ;;
235
+ --no-tests)
236
+ skip_tests=true
237
+ shift
238
+ ;;
239
+ --force-rebuild)
240
+ force_rebuild=true
241
+ shift
242
+ ;;
243
+ *)
244
+ log $RED "Unknown option: $1"
245
+ show_help
246
+ exit 1
247
+ ;;
248
+ esac
249
+ done
250
+
251
+ log $GREEN "🚀 Starting mongory-rb build process..."
252
+
253
+ # Clean and exit if requested
254
+ if $clean_only; then
255
+ clean
256
+ exit 0
257
+ fi
258
+
259
+ # Force rebuild if requested
260
+ if $force_rebuild; then
261
+ clean
262
+ fi
263
+
264
+ # Check dependencies unless skipped
265
+ if ! $skip_deps; then
266
+ check_dependencies
267
+ fi
268
+
269
+ # Initialize submodules
270
+ init_submodules
271
+
272
+ # Build mongory-core
273
+ build_core
274
+
275
+ # Build Ruby C extension
276
+ if $debug_mode; then
277
+ build_extension --debug
278
+ else
279
+ build_extension
280
+ fi
281
+
282
+ # Run tests unless skipped
283
+ if ! $skip_tests; then
284
+ run_tests
285
+ fi
286
+
287
+ log $GREEN "🎉 Build completed successfully!"
288
+ log $BLUE "You can now use mongory-rb with C extension support."
289
+ }
290
+
291
+ # Run main function with all arguments
292
+ main "$@"
metadata CHANGED
@@ -1,20 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.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-24 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2025-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  description: A Mongo-like in-memory query DSL for Ruby
14
28
  email:
15
29
  - koten0224@gmail.com
16
30
  executables: []
17
- extensions: []
31
+ extensions:
32
+ - ext/mongory_ext/extconf.rb
18
33
  extra_rdoc_files: []
19
34
  files:
20
35
  - ".rspec"
@@ -25,15 +40,64 @@ files:
25
40
  - LICENSE.txt
26
41
  - README.md
27
42
  - Rakefile
43
+ - SUBMODULE_INTEGRATION.md
44
+ - docs/advanced_usage.md
45
+ - docs/clang_bridge.md
46
+ - docs/field_names.md
47
+ - docs/migration.md
48
+ - docs/performance.md
28
49
  - examples/README.md
29
50
  - examples/benchmark-rails.rb
30
51
  - examples/benchmark.rb
52
+ - ext/mongory_ext/extconf.rb
53
+ - ext/mongory_ext/mongory-core/LICENSE
54
+ - ext/mongory_ext/mongory-core/include/mongory-core.h
55
+ - ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h
56
+ - ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h
57
+ - ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h
58
+ - ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h
59
+ - ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h
60
+ - ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h
61
+ - ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h
62
+ - ext/mongory_ext/mongory-core/src/foundations/array.c
63
+ - ext/mongory_ext/mongory-core/src/foundations/array_private.h
64
+ - ext/mongory_ext/mongory-core/src/foundations/config.c
65
+ - ext/mongory_ext/mongory-core/src/foundations/config_private.h
66
+ - ext/mongory_ext/mongory-core/src/foundations/error.c
67
+ - ext/mongory_ext/mongory-core/src/foundations/memory_pool.c
68
+ - ext/mongory_ext/mongory-core/src/foundations/string_buffer.c
69
+ - ext/mongory_ext/mongory-core/src/foundations/string_buffer.h
70
+ - ext/mongory_ext/mongory-core/src/foundations/table.c
71
+ - ext/mongory_ext/mongory-core/src/foundations/value.c
72
+ - ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c
73
+ - ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h
74
+ - ext/mongory_ext/mongory-core/src/matchers/base_matcher.c
75
+ - ext/mongory_ext/mongory-core/src/matchers/base_matcher.h
76
+ - ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c
77
+ - ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h
78
+ - ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c
79
+ - ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h
80
+ - ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c
81
+ - ext/mongory_ext/mongory-core/src/matchers/existance_matcher.h
82
+ - ext/mongory_ext/mongory-core/src/matchers/external_matcher.c
83
+ - ext/mongory_ext/mongory-core/src/matchers/external_matcher.h
84
+ - ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c
85
+ - ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h
86
+ - ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c
87
+ - ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h
88
+ - ext/mongory_ext/mongory-core/src/matchers/matcher.c
89
+ - ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c
90
+ - ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h
91
+ - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c
92
+ - ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h
93
+ - ext/mongory_ext/mongory_ext.c
31
94
  - lib/generators/mongory/install/install_generator.rb
32
95
  - lib/generators/mongory/install/templates/initializer.rb.erb
33
96
  - lib/generators/mongory/matcher/matcher_generator.rb
34
97
  - lib/generators/mongory/matcher/templates/matcher.rb.erb
35
98
  - lib/generators/mongory/matcher/templates/matcher_spec.rb.erb
36
99
  - lib/mongory.rb
100
+ - lib/mongory/c_query_builder.rb
37
101
  - lib/mongory/converters.rb
38
102
  - lib/mongory/converters/abstract_converter.rb
39
103
  - lib/mongory/converters/condition_converter.rb
@@ -77,6 +141,7 @@ files:
77
141
  - lib/mongory/utils/singleton_builder.rb
78
142
  - lib/mongory/version.rb
79
143
  - mongory.gemspec
144
+ - scripts/build_with_core.sh
80
145
  - sig/mongory.rbs
81
146
  homepage: https://mongoryhq.github.io/mongory-rb/
82
147
  licenses:
@@ -102,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
167
  - !ruby/object:Gem::Version
103
168
  version: '0'
104
169
  requirements: []
105
- rubygems_version: 3.0.8
170
+ rubygems_version: 3.1.6
106
171
  signing_key:
107
172
  specification_version: 4
108
173
  summary: MongoDB-like in-memory query DSL for Ruby