contextual_config 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7f59ad6d1973f90217140881d7cf16006e9a0447641b4f7cc2cd18116a97e2cb
4
+ data.tar.gz: ec5e9472a87b390f4f1b720c9a970cd39dbe498acf0e501722662d9bcfb5bc16
5
+ SHA512:
6
+ metadata.gz: 96eec3b206c9f1138954885d5ba7af8c4f64751677ce41061829953278dd3e71c9f5f3f18de2a159b61259a7fae06c976b5c6dcfda0d04e99d30d85e62cb6f5b
7
+ data.tar.gz: 11bb322511c97d471442f84949f182758c97b45dba6938c59e03c7bbb9160bc2163f15565ba71a81d8a0e26710941149d882e1eee3a4a8ad44df15efd29468c9
@@ -0,0 +1,14 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "mcp__filesystem__read_multiple_files",
5
+ "Bash(bundle install)",
6
+ "Bash(bundle exec rspec:*)",
7
+ "Bash(bundle exec rubocop:*)",
8
+ "Bash(grep:*)",
9
+ "Bash(git config:*)",
10
+ "Bash(git add:*)"
11
+ ],
12
+ "deny": []
13
+ }
14
+ }
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CLAUDE.md ADDED
@@ -0,0 +1,66 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Development Commands
6
+
7
+ - **Run tests**: `bundle exec rake spec` or `bundle exec rspec`
8
+ - **Run linting**: `bundle exec rubocop`
9
+ - **Run both tests and linting**: `bundle exec rake` (default task)
10
+ - **Auto-fix linting issues**: `bundle exec rubocop -A`
11
+ - **Install dependencies**: `bundle install`
12
+ - **Run specific test**: `bundle exec rspec spec/path/to/specific_spec.rb`
13
+ - **Run test with focus**: `bundle exec rspec --tag focus` (for tests marked with `focus: true`)
14
+
15
+ ## Architecture Overview
16
+
17
+ ContextualConfig is a Ruby gem for context-aware configuration management built around three core architectural layers:
18
+
19
+ ### 1. Core Concerns (lib/contextual_config/concern/)
20
+
21
+ - **Configurable**: Provides validations, scopes, and basic configuration functionality. Expects database columns: `key`, `config_data` (jsonb), `scoping_rules` (jsonb), `priority` (integer), `is_active` (boolean)
22
+ - **Lookupable**: Handles configuration lookup logic with `find_applicable_config(key:, context:)` and `find_all_applicable_configs(context:)`
23
+ - **SchemaDrivenValidation**: Optional JSON schema validation for `config_data` and `scoping_rules`
24
+
25
+ ### 2. Matching Engine (lib/contextual_config/services/)
26
+
27
+ - **ContextualMatcher**: Core matching logic that evaluates scoping rules against context
28
+ - Uses specificity scoring (more specific rules win) and priority ordering (lower numbers = higher priority)
29
+ - Special handling for timing rules with date range evaluation
30
+ - Supports extensible rule types through private methods like `evaluate_timing_rule`
31
+
32
+ ### 3. Configuration Management
33
+
34
+ - **Configuration**: Global gem settings for caching, logging, timing evaluation
35
+ - **ModuleRegistry**: Allows modules to register custom configurations and model classes
36
+ - **Generators**: Rails generator for creating configuration tables with proper indexes
37
+
38
+ ### Key Design Patterns
39
+
40
+ - **Context-driven matching**: Configurations match based on runtime context hash
41
+ - **Priority + Specificity resolution**: More specific rules beat less specific, higher priority (lower number) wins ties
42
+ - **JSONB-based flexibility**: Both config data and scoping rules stored as JSONB for schema flexibility
43
+ - **Concerns-based modularity**: Mix and match functionality via ActiveSupport::Concern modules
44
+ - **Service-based matching**: Centralized matching logic in ContextualMatcher service
45
+
46
+ ### Database Schema Expectations
47
+
48
+ Models using these concerns should have:
49
+ ```ruby
50
+ t.string :key, null: false
51
+ t.jsonb :config_data, null: false, default: {}
52
+ t.jsonb :scoping_rules, null: false, default: {}
53
+ t.integer :priority, null: false, default: 100
54
+ t.boolean :is_active, null: false, default: true
55
+ t.text :description
56
+ t.string :type # For STI if needed
57
+ ```
58
+
59
+ ### Testing Strategy
60
+
61
+ - In-memory SQLite database for fast test runs (95 passing tests)
62
+ - Concerns tested independently and through integration tests
63
+ - Database cleaned between each test run
64
+ - RSpec configuration in `spec/spec_helper.rb` sets up test schema and database
65
+ - JSON serialization used for SQLite compatibility (instead of JSONB)
66
+ - Comprehensive test coverage for matching logic, caching, logging, and validation
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in contextual_config.gemspec
4
+ gemspec
5
+
6
+ # Development tools not included in gemspec development dependencies
7
+ gem 'rake', '~> 13.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,295 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ contextual_config (0.1.0)
5
+ activerecord (>= 6.0)
6
+ activesupport (>= 6.0)
7
+ json-schema (~> 5.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (8.0.2)
13
+ actionpack (= 8.0.2)
14
+ activesupport (= 8.0.2)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ zeitwerk (~> 2.6)
18
+ actionmailbox (8.0.2)
19
+ actionpack (= 8.0.2)
20
+ activejob (= 8.0.2)
21
+ activerecord (= 8.0.2)
22
+ activestorage (= 8.0.2)
23
+ activesupport (= 8.0.2)
24
+ mail (>= 2.8.0)
25
+ actionmailer (8.0.2)
26
+ actionpack (= 8.0.2)
27
+ actionview (= 8.0.2)
28
+ activejob (= 8.0.2)
29
+ activesupport (= 8.0.2)
30
+ mail (>= 2.8.0)
31
+ rails-dom-testing (~> 2.2)
32
+ actionpack (8.0.2)
33
+ actionview (= 8.0.2)
34
+ activesupport (= 8.0.2)
35
+ nokogiri (>= 1.8.5)
36
+ rack (>= 2.2.4)
37
+ rack-session (>= 1.0.1)
38
+ rack-test (>= 0.6.3)
39
+ rails-dom-testing (~> 2.2)
40
+ rails-html-sanitizer (~> 1.6)
41
+ useragent (~> 0.16)
42
+ actiontext (8.0.2)
43
+ actionpack (= 8.0.2)
44
+ activerecord (= 8.0.2)
45
+ activestorage (= 8.0.2)
46
+ activesupport (= 8.0.2)
47
+ globalid (>= 0.6.0)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (8.0.2)
50
+ activesupport (= 8.0.2)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.11)
53
+ rails-dom-testing (~> 2.2)
54
+ rails-html-sanitizer (~> 1.6)
55
+ activejob (8.0.2)
56
+ activesupport (= 8.0.2)
57
+ globalid (>= 0.3.6)
58
+ activemodel (8.0.2)
59
+ activesupport (= 8.0.2)
60
+ activerecord (8.0.2)
61
+ activemodel (= 8.0.2)
62
+ activesupport (= 8.0.2)
63
+ timeout (>= 0.4.0)
64
+ activestorage (8.0.2)
65
+ actionpack (= 8.0.2)
66
+ activejob (= 8.0.2)
67
+ activerecord (= 8.0.2)
68
+ activesupport (= 8.0.2)
69
+ marcel (~> 1.0)
70
+ activesupport (8.0.2)
71
+ base64
72
+ benchmark (>= 0.3)
73
+ bigdecimal
74
+ concurrent-ruby (~> 1.0, >= 1.3.1)
75
+ connection_pool (>= 2.2.5)
76
+ drb
77
+ i18n (>= 1.6, < 2)
78
+ logger (>= 1.4.2)
79
+ minitest (>= 5.1)
80
+ securerandom (>= 0.3)
81
+ tzinfo (~> 2.0, >= 2.0.5)
82
+ uri (>= 0.13.1)
83
+ addressable (2.8.7)
84
+ public_suffix (>= 2.0.2, < 7.0)
85
+ ast (2.4.3)
86
+ base64 (0.3.0)
87
+ benchmark (0.4.1)
88
+ bigdecimal (3.2.2)
89
+ builder (3.3.0)
90
+ concurrent-ruby (1.3.5)
91
+ connection_pool (2.5.3)
92
+ crass (1.0.6)
93
+ date (3.4.1)
94
+ diff-lcs (1.6.2)
95
+ drb (2.2.3)
96
+ erb (5.0.1)
97
+ erubi (1.13.1)
98
+ globalid (1.2.1)
99
+ activesupport (>= 6.1)
100
+ i18n (1.14.7)
101
+ concurrent-ruby (~> 1.0)
102
+ io-console (0.8.0)
103
+ irb (1.15.2)
104
+ pp (>= 0.6.0)
105
+ rdoc (>= 4.0.0)
106
+ reline (>= 0.4.2)
107
+ json (2.12.2)
108
+ json-schema (5.1.1)
109
+ addressable (~> 2.8)
110
+ bigdecimal (~> 3.1)
111
+ language_server-protocol (3.17.0.5)
112
+ lint_roller (1.1.0)
113
+ logger (1.7.0)
114
+ loofah (2.24.1)
115
+ crass (~> 1.0.2)
116
+ nokogiri (>= 1.12.0)
117
+ mail (2.8.1)
118
+ mini_mime (>= 0.1.1)
119
+ net-imap
120
+ net-pop
121
+ net-smtp
122
+ marcel (1.0.4)
123
+ mini_mime (1.1.5)
124
+ minitest (5.25.5)
125
+ net-imap (0.5.8)
126
+ date
127
+ net-protocol
128
+ net-pop (0.1.2)
129
+ net-protocol
130
+ net-protocol (0.2.2)
131
+ timeout
132
+ net-smtp (0.5.1)
133
+ net-protocol
134
+ nio4r (2.7.4)
135
+ nokogiri (1.18.8-aarch64-linux-gnu)
136
+ racc (~> 1.4)
137
+ nokogiri (1.18.8-aarch64-linux-musl)
138
+ racc (~> 1.4)
139
+ nokogiri (1.18.8-arm-linux-gnu)
140
+ racc (~> 1.4)
141
+ nokogiri (1.18.8-arm-linux-musl)
142
+ racc (~> 1.4)
143
+ nokogiri (1.18.8-arm64-darwin)
144
+ racc (~> 1.4)
145
+ nokogiri (1.18.8-x86_64-darwin)
146
+ racc (~> 1.4)
147
+ nokogiri (1.18.8-x86_64-linux-gnu)
148
+ racc (~> 1.4)
149
+ nokogiri (1.18.8-x86_64-linux-musl)
150
+ racc (~> 1.4)
151
+ parallel (1.27.0)
152
+ parser (3.3.8.0)
153
+ ast (~> 2.4.1)
154
+ racc
155
+ pp (0.6.2)
156
+ prettyprint
157
+ prettyprint (0.2.0)
158
+ prism (1.4.0)
159
+ psych (5.2.6)
160
+ date
161
+ stringio
162
+ public_suffix (6.0.2)
163
+ racc (1.8.1)
164
+ rack (3.1.16)
165
+ rack-session (2.1.1)
166
+ base64 (>= 0.1.0)
167
+ rack (>= 3.0.0)
168
+ rack-test (2.2.0)
169
+ rack (>= 1.3)
170
+ rackup (2.2.1)
171
+ rack (>= 3)
172
+ rails (8.0.2)
173
+ actioncable (= 8.0.2)
174
+ actionmailbox (= 8.0.2)
175
+ actionmailer (= 8.0.2)
176
+ actionpack (= 8.0.2)
177
+ actiontext (= 8.0.2)
178
+ actionview (= 8.0.2)
179
+ activejob (= 8.0.2)
180
+ activemodel (= 8.0.2)
181
+ activerecord (= 8.0.2)
182
+ activestorage (= 8.0.2)
183
+ activesupport (= 8.0.2)
184
+ bundler (>= 1.15.0)
185
+ railties (= 8.0.2)
186
+ rails-dom-testing (2.3.0)
187
+ activesupport (>= 5.0.0)
188
+ minitest
189
+ nokogiri (>= 1.6)
190
+ rails-html-sanitizer (1.6.2)
191
+ loofah (~> 2.21)
192
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
193
+ railties (8.0.2)
194
+ actionpack (= 8.0.2)
195
+ activesupport (= 8.0.2)
196
+ irb (~> 1.13)
197
+ rackup (>= 1.0.0)
198
+ rake (>= 12.2)
199
+ thor (~> 1.0, >= 1.2.2)
200
+ zeitwerk (~> 2.6)
201
+ rainbow (3.1.1)
202
+ rake (13.3.0)
203
+ rdoc (6.14.0)
204
+ erb
205
+ psych (>= 4.0.0)
206
+ regexp_parser (2.10.0)
207
+ reline (0.6.1)
208
+ io-console (~> 0.5)
209
+ rspec (3.13.1)
210
+ rspec-core (~> 3.13.0)
211
+ rspec-expectations (~> 3.13.0)
212
+ rspec-mocks (~> 3.13.0)
213
+ rspec-core (3.13.4)
214
+ rspec-support (~> 3.13.0)
215
+ rspec-expectations (3.13.5)
216
+ diff-lcs (>= 1.2.0, < 2.0)
217
+ rspec-support (~> 3.13.0)
218
+ rspec-mocks (3.13.5)
219
+ diff-lcs (>= 1.2.0, < 2.0)
220
+ rspec-support (~> 3.13.0)
221
+ rspec-support (3.13.4)
222
+ rubocop (1.76.0)
223
+ json (~> 2.3)
224
+ language_server-protocol (~> 3.17.0.2)
225
+ lint_roller (~> 1.1.0)
226
+ parallel (~> 1.10)
227
+ parser (>= 3.3.0.2)
228
+ rainbow (>= 2.2.2, < 4.0)
229
+ regexp_parser (>= 2.9.3, < 3.0)
230
+ rubocop-ast (>= 1.45.0, < 2.0)
231
+ ruby-progressbar (~> 1.7)
232
+ unicode-display_width (>= 2.4.0, < 4.0)
233
+ rubocop-ast (1.45.0)
234
+ parser (>= 3.3.7.2)
235
+ prism (~> 1.4)
236
+ rubocop-rails (2.32.0)
237
+ activesupport (>= 4.2.0)
238
+ lint_roller (~> 1.1)
239
+ rack (>= 1.1)
240
+ rubocop (>= 1.75.0, < 2.0)
241
+ rubocop-ast (>= 1.44.0, < 2.0)
242
+ rubocop-rspec (3.6.0)
243
+ lint_roller (~> 1.1)
244
+ rubocop (~> 1.72, >= 1.72.1)
245
+ ruby-progressbar (1.13.0)
246
+ securerandom (0.4.1)
247
+ sqlite3 (2.6.0-aarch64-linux-gnu)
248
+ sqlite3 (2.6.0-aarch64-linux-musl)
249
+ sqlite3 (2.6.0-arm-linux-gnu)
250
+ sqlite3 (2.6.0-arm-linux-musl)
251
+ sqlite3 (2.6.0-arm64-darwin)
252
+ sqlite3 (2.6.0-x86_64-darwin)
253
+ sqlite3 (2.6.0-x86_64-linux-gnu)
254
+ sqlite3 (2.6.0-x86_64-linux-musl)
255
+ stringio (3.1.7)
256
+ thor (1.3.2)
257
+ timeout (0.4.3)
258
+ tzinfo (2.0.6)
259
+ concurrent-ruby (~> 1.0)
260
+ unicode-display_width (3.1.4)
261
+ unicode-emoji (~> 4.0, >= 4.0.4)
262
+ unicode-emoji (4.0.4)
263
+ uri (1.0.3)
264
+ useragent (0.16.11)
265
+ websocket-driver (0.8.0)
266
+ base64
267
+ websocket-extensions (>= 0.1.0)
268
+ websocket-extensions (0.1.5)
269
+ zeitwerk (2.7.3)
270
+
271
+ PLATFORMS
272
+ aarch64-linux
273
+ aarch64-linux-gnu
274
+ aarch64-linux-musl
275
+ arm-linux
276
+ arm-linux-gnu
277
+ arm-linux-musl
278
+ arm64-darwin
279
+ x86_64-darwin
280
+ x86_64-linux
281
+ x86_64-linux-gnu
282
+ x86_64-linux-musl
283
+
284
+ DEPENDENCIES
285
+ contextual_config!
286
+ rails (>= 6.0)
287
+ rake (~> 13.0)
288
+ rspec (~> 3.0)
289
+ rubocop (~> 1.0)
290
+ rubocop-rails (~> 2.0)
291
+ rubocop-rspec (~> 3.0)
292
+ sqlite3 (>= 2.1)
293
+
294
+ BUNDLED WITH
295
+ 2.6.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Vishal (vishal18593@gmail.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.