json-guard 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: 538d9b01c51547693e32498eee02dd18a73fdfe6948412cbe66866e7335d20ee
4
+ data.tar.gz: 2b3aab9691505edd14a2e2b23a14cf39579aaabfe84405498abf6ae847426da4
5
+ SHA512:
6
+ metadata.gz: bd6d17f87af558ef6b673a5b94db4c5a1d4428e194893aa12613c72aeeb5a4b5b18ca596cfccc24cb1daf612021cacf76e1c6b9e2fbdb02aa401acb14151c555
7
+ data.tar.gz: 8fe49c82d234ccd4326b168ba14fcba628adc5740e768815d289e155f616409de83c214d3f55b81c4516544baaa0924f0c17cd17e6a3bd8202389d7a3f689a87
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial gem structure
12
+ - Basic JSON Schema validation
13
+ - Rails integration
14
+ - Context-aware validation
15
+ - Multiple message types support
16
+ - Performance optimizations
17
+
18
+ ## [0.1.0] - 2025-07-06
19
+
20
+ ### Added
21
+ - Initial release
22
+ - Basic JSON Schema validation for Rails
23
+ - ActiveRecord integration
24
+ - Custom error messages
25
+ - Schema DSL
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,257 @@
1
+ # Contributing to JsonGuard
2
+
3
+ We love your input! We want to make contributing to JsonGuard as easy and transparent as possible, whether it's:
4
+
5
+ - Reporting a bug
6
+ - Discussing the current state of the code
7
+ - Submitting a fix
8
+ - Proposing new features
9
+ - Becoming a maintainer
10
+
11
+ ## 🚀 Getting Started
12
+
13
+ 1. **Fork the repository** on GitHub
14
+ 2. **Clone your fork** locally:
15
+ ```bash
16
+ git clone https://github.com/YOUR-USERNAME/json-guard.git
17
+ cd json-guard
18
+ ```
19
+ 3. **Install dependencies**:
20
+ ```bash
21
+ bundle install
22
+ ```
23
+ 4. **Run the tests** to make sure everything works:
24
+ ```bash
25
+ bundle exec rspec
26
+ ```
27
+
28
+ ## 🐛 Reporting Bugs
29
+
30
+ We use GitHub Issues to track bugs. Report a bug by [opening a new issue](https://github.com/zaid-4/json-guard/issues/new).
31
+
32
+ ### Great Bug Reports Include:
33
+
34
+ - **Summary**: A quick summary of the issue
35
+ - **Steps to reproduce**: Be specific!
36
+ - **Expected behavior**: What you expected to happen
37
+ - **Actual behavior**: What actually happened
38
+ - **Environment**: Ruby version, Rails version, etc.
39
+ - **Sample code**: If possible, provide a minimal code example
40
+
41
+ ### Example Bug Report:
42
+
43
+ ```markdown
44
+ ## Summary
45
+ Schema validation fails with nested arrays of objects
46
+
47
+ ## Steps to Reproduce
48
+ 1. Define a schema with nested array of objects
49
+ 2. Validate data with valid nested structure
50
+ 3. Validation fails unexpectedly
51
+
52
+ ## Expected Behavior
53
+ Validation should pass for valid nested array data
54
+
55
+ ## Actual Behavior
56
+ Validation fails with "invalid type" error
57
+
58
+ ## Environment
59
+ - Ruby: 3.0.0
60
+ - Rails: 7.0.0
61
+ - JsonGuard: 0.1.0
62
+
63
+ ## Sample Code
64
+ ```ruby
65
+ class TestSchema < JsonGuard::Schema
66
+ items :array, items: {
67
+ type: :object,
68
+ properties: {
69
+ name: { type: :string, required: true }
70
+ }
71
+ }
72
+ end
73
+
74
+ data = { items: [{ name: "test" }] }
75
+ validator = JsonGuard::Validator.new(TestSchema)
76
+ validator.validate(data) # => false (should be true)
77
+ ```
78
+ ```
79
+
80
+ ## 🔧 Making Changes
81
+
82
+ 1. **Create a branch** for your changes:
83
+ ```bash
84
+ git checkout -b feature/amazing-feature
85
+ ```
86
+
87
+ 2. **Make your changes** and add tests
88
+
89
+ 3. **Run the test suite**:
90
+ ```bash
91
+ bundle exec rspec
92
+ ```
93
+
94
+ 4. **Run RuboCop** to check code style:
95
+ ```bash
96
+ bundle exec rubocop
97
+ ```
98
+
99
+ 5. **Commit your changes**:
100
+ ```bash
101
+ git commit -m "Add amazing feature"
102
+ ```
103
+
104
+ 6. **Push to your fork**:
105
+ ```bash
106
+ git push origin feature/amazing-feature
107
+ ```
108
+
109
+ 7. **Create a Pull Request**
110
+
111
+ ## 🧪 Testing
112
+
113
+ ### Running Tests
114
+
115
+ ```bash
116
+ # Run all tests
117
+ bundle exec rspec
118
+
119
+ # Run specific test file
120
+ bundle exec rspec spec/json_guard/schema_spec.rb
121
+
122
+ # Run tests with coverage
123
+ bundle exec rspec --format documentation
124
+
125
+ # Run a specific test
126
+ bundle exec rspec spec/json_guard/schema_spec.rb:25
127
+ ```
128
+
129
+ ### Writing Tests
130
+
131
+ - Write tests for all new functionality
132
+ - Follow existing test patterns
133
+ - Use descriptive test names
134
+ - Include both positive and negative test cases
135
+
136
+ Example test:
137
+
138
+ ```ruby
139
+ RSpec.describe JsonGuard::Schema do
140
+ describe "new feature" do
141
+ it "does something useful" do
142
+ # Test implementation
143
+ expect(result).to eq(expected_value)
144
+ end
145
+
146
+ it "handles edge cases" do
147
+ # Test edge cases
148
+ expect { problematic_code }.to raise_error(SpecificError)
149
+ end
150
+ end
151
+ end
152
+ ```
153
+
154
+ ## 📝 Code Style
155
+
156
+ We use RuboCop to enforce consistent code style:
157
+
158
+ ```bash
159
+ # Check code style
160
+ bundle exec rubocop
161
+
162
+ # Auto-fix issues where possible
163
+ bundle exec rubocop -a
164
+ ```
165
+
166
+ ### Style Guidelines:
167
+
168
+ - Use 2 spaces for indentation
169
+ - Keep lines under 100 characters
170
+ - Use meaningful variable and method names
171
+ - Add comments for complex logic
172
+ - Follow Ruby and Rails conventions
173
+
174
+ ## 🎯 Pull Request Process
175
+
176
+ 1. **Update documentation** if needed
177
+ 2. **Add tests** for new functionality
178
+ 3. **Ensure all tests pass**
179
+ 4. **Update CHANGELOG.md** with your changes
180
+ 5. **Make sure code follows style guidelines**
181
+
182
+ ### Pull Request Template:
183
+
184
+ ```markdown
185
+ ## Description
186
+ Brief description of changes
187
+
188
+ ## Type of Change
189
+ - [ ] Bug fix
190
+ - [ ] New feature
191
+ - [ ] Breaking change
192
+ - [ ] Documentation update
193
+
194
+ ## Testing
195
+ - [ ] Added tests for new functionality
196
+ - [ ] All existing tests pass
197
+ - [ ] Manual testing completed
198
+
199
+ ## Checklist
200
+ - [ ] Code follows style guidelines
201
+ - [ ] Self-review completed
202
+ - [ ] Documentation updated
203
+ - [ ] CHANGELOG.md updated
204
+ ```
205
+
206
+ ## 🏷️ Versioning
207
+
208
+ We use [Semantic Versioning](https://semver.org/):
209
+
210
+ - **MAJOR**: Breaking changes
211
+ - **MINOR**: New features (backward compatible)
212
+ - **PATCH**: Bug fixes (backward compatible)
213
+
214
+ ## 📋 Feature Requests
215
+
216
+ We welcome feature requests! Please:
217
+
218
+ 1. **Check existing issues** first
219
+ 2. **Create a new issue** with the "enhancement" label
220
+ 3. **Describe the feature** and its use case
221
+ 4. **Explain why** it would be useful
222
+ 5. **Provide examples** if possible
223
+
224
+ ## 🤝 Code of Conduct
225
+
226
+ ### Our Pledge
227
+
228
+ We pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
229
+
230
+ ### Our Standards
231
+
232
+ Examples of behavior that contributes to creating a positive environment:
233
+
234
+ - Using welcoming and inclusive language
235
+ - Being respectful of differing viewpoints and experiences
236
+ - Gracefully accepting constructive criticism
237
+ - Focusing on what is best for the community
238
+ - Showing empathy towards other community members
239
+
240
+ ### Enforcement
241
+
242
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at izaidsaeed@gmail.com.
243
+
244
+ ## 📧 Contact
245
+
246
+ - **GitHub**: [@zaid-4](https://github.com/zaid-4)
247
+ - **Email**: izaidsaeed@gmail.com
248
+
249
+ ## 🙏 Recognition
250
+
251
+ Contributors will be recognized in:
252
+
253
+ - **README.md** contributors section
254
+ - **CHANGELOG.md** for their specific contributions
255
+ - **GitHub contributors** page
256
+
257
+ Thank you for contributing to JsonGuard! 🎉
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in json-guard.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,255 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ json-guard (0.1.0)
5
+ activesupport (~> 6.0)
6
+ json-schema (~> 4.0)
7
+ rails (~> 6.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (6.1.7.10)
13
+ actionpack (= 6.1.7.10)
14
+ activesupport (= 6.1.7.10)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ actionmailbox (6.1.7.10)
18
+ actionpack (= 6.1.7.10)
19
+ activejob (= 6.1.7.10)
20
+ activerecord (= 6.1.7.10)
21
+ activestorage (= 6.1.7.10)
22
+ activesupport (= 6.1.7.10)
23
+ mail (>= 2.7.1)
24
+ actionmailer (6.1.7.10)
25
+ actionpack (= 6.1.7.10)
26
+ actionview (= 6.1.7.10)
27
+ activejob (= 6.1.7.10)
28
+ activesupport (= 6.1.7.10)
29
+ mail (~> 2.5, >= 2.5.4)
30
+ rails-dom-testing (~> 2.0)
31
+ actionpack (6.1.7.10)
32
+ actionview (= 6.1.7.10)
33
+ activesupport (= 6.1.7.10)
34
+ rack (~> 2.0, >= 2.0.9)
35
+ rack-test (>= 0.6.3)
36
+ rails-dom-testing (~> 2.0)
37
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
38
+ actiontext (6.1.7.10)
39
+ actionpack (= 6.1.7.10)
40
+ activerecord (= 6.1.7.10)
41
+ activestorage (= 6.1.7.10)
42
+ activesupport (= 6.1.7.10)
43
+ nokogiri (>= 1.8.5)
44
+ actionview (6.1.7.10)
45
+ activesupport (= 6.1.7.10)
46
+ builder (~> 3.1)
47
+ erubi (~> 1.4)
48
+ rails-dom-testing (~> 2.0)
49
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
50
+ activejob (6.1.7.10)
51
+ activesupport (= 6.1.7.10)
52
+ globalid (>= 0.3.6)
53
+ activemodel (6.1.7.10)
54
+ activesupport (= 6.1.7.10)
55
+ activerecord (6.1.7.10)
56
+ activemodel (= 6.1.7.10)
57
+ activesupport (= 6.1.7.10)
58
+ activestorage (6.1.7.10)
59
+ actionpack (= 6.1.7.10)
60
+ activejob (= 6.1.7.10)
61
+ activerecord (= 6.1.7.10)
62
+ activesupport (= 6.1.7.10)
63
+ marcel (~> 1.0)
64
+ mini_mime (>= 1.1.0)
65
+ activesupport (6.1.7.10)
66
+ concurrent-ruby (~> 1.0, >= 1.0.2)
67
+ i18n (>= 1.6, < 2)
68
+ minitest (>= 5.1)
69
+ tzinfo (~> 2.0)
70
+ zeitwerk (~> 2.3)
71
+ addressable (2.8.7)
72
+ public_suffix (>= 2.0.2, < 7.0)
73
+ ast (2.4.3)
74
+ base64 (0.3.0)
75
+ builder (3.3.0)
76
+ coderay (1.1.3)
77
+ concurrent-ruby (1.3.5)
78
+ crass (1.0.6)
79
+ date (3.4.1)
80
+ diff-lcs (1.6.2)
81
+ docile (1.4.1)
82
+ erubi (1.13.1)
83
+ globalid (1.2.1)
84
+ activesupport (>= 6.1)
85
+ i18n (1.14.7)
86
+ concurrent-ruby (~> 1.0)
87
+ json (2.13.2)
88
+ json-schema (4.3.1)
89
+ addressable (>= 2.8)
90
+ language_server-protocol (3.17.0.5)
91
+ lint_roller (1.1.0)
92
+ logger (1.7.0)
93
+ loofah (2.24.1)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.12.0)
96
+ mail (2.8.1)
97
+ mini_mime (>= 0.1.1)
98
+ net-imap
99
+ net-pop
100
+ net-smtp
101
+ marcel (1.0.4)
102
+ method_source (1.1.0)
103
+ mini_mime (1.1.5)
104
+ mini_portile2 (2.8.9)
105
+ minitest (5.25.5)
106
+ net-imap (0.5.9)
107
+ date
108
+ net-protocol
109
+ net-pop (0.1.2)
110
+ net-protocol
111
+ net-protocol (0.2.2)
112
+ timeout
113
+ net-smtp (0.5.1)
114
+ net-protocol
115
+ nio4r (2.7.4)
116
+ nokogiri (1.18.9)
117
+ mini_portile2 (~> 2.8.2)
118
+ racc (~> 1.4)
119
+ nokogiri (1.18.9-x86_64-linux-gnu)
120
+ racc (~> 1.4)
121
+ parallel (1.27.0)
122
+ parser (3.3.9.0)
123
+ ast (~> 2.4.1)
124
+ racc
125
+ prism (1.4.0)
126
+ pry (0.15.2)
127
+ coderay (~> 1.1)
128
+ method_source (~> 1.0)
129
+ public_suffix (6.0.2)
130
+ racc (1.8.1)
131
+ rack (2.2.17)
132
+ rack-test (2.2.0)
133
+ rack (>= 1.3)
134
+ rails (6.1.7.10)
135
+ actioncable (= 6.1.7.10)
136
+ actionmailbox (= 6.1.7.10)
137
+ actionmailer (= 6.1.7.10)
138
+ actionpack (= 6.1.7.10)
139
+ actiontext (= 6.1.7.10)
140
+ actionview (= 6.1.7.10)
141
+ activejob (= 6.1.7.10)
142
+ activemodel (= 6.1.7.10)
143
+ activerecord (= 6.1.7.10)
144
+ activestorage (= 6.1.7.10)
145
+ activesupport (= 6.1.7.10)
146
+ bundler (>= 1.15.0)
147
+ railties (= 6.1.7.10)
148
+ sprockets-rails (>= 2.0.0)
149
+ rails-dom-testing (2.3.0)
150
+ activesupport (>= 5.0.0)
151
+ minitest
152
+ nokogiri (>= 1.6)
153
+ rails-html-sanitizer (1.6.2)
154
+ loofah (~> 2.21)
155
+ 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)
156
+ railties (6.1.7.10)
157
+ actionpack (= 6.1.7.10)
158
+ activesupport (= 6.1.7.10)
159
+ method_source
160
+ rake (>= 12.2)
161
+ thor (~> 1.0)
162
+ rainbow (3.1.1)
163
+ rake (13.3.0)
164
+ regexp_parser (2.10.0)
165
+ rspec (3.13.1)
166
+ rspec-core (~> 3.13.0)
167
+ rspec-expectations (~> 3.13.0)
168
+ rspec-mocks (~> 3.13.0)
169
+ rspec-core (3.13.5)
170
+ rspec-support (~> 3.13.0)
171
+ rspec-expectations (3.13.5)
172
+ diff-lcs (>= 1.2.0, < 2.0)
173
+ rspec-support (~> 3.13.0)
174
+ rspec-mocks (3.13.5)
175
+ diff-lcs (>= 1.2.0, < 2.0)
176
+ rspec-support (~> 3.13.0)
177
+ rspec-rails (6.1.5)
178
+ actionpack (>= 6.1)
179
+ activesupport (>= 6.1)
180
+ railties (>= 6.1)
181
+ rspec-core (~> 3.13)
182
+ rspec-expectations (~> 3.13)
183
+ rspec-mocks (~> 3.13)
184
+ rspec-support (~> 3.13)
185
+ rspec-support (3.13.4)
186
+ rubocop (1.79.0)
187
+ json (~> 2.3)
188
+ language_server-protocol (~> 3.17.0.2)
189
+ lint_roller (~> 1.1.0)
190
+ parallel (~> 1.10)
191
+ parser (>= 3.3.0.2)
192
+ rainbow (>= 2.2.2, < 4.0)
193
+ regexp_parser (>= 2.9.3, < 3.0)
194
+ rubocop-ast (>= 1.46.0, < 2.0)
195
+ ruby-progressbar (~> 1.7)
196
+ tsort (>= 0.2.0)
197
+ unicode-display_width (>= 2.4.0, < 4.0)
198
+ rubocop-ast (1.46.0)
199
+ parser (>= 3.3.7.2)
200
+ prism (~> 1.4)
201
+ rubocop-rails (2.32.0)
202
+ activesupport (>= 4.2.0)
203
+ lint_roller (~> 1.1)
204
+ rack (>= 1.1)
205
+ rubocop (>= 1.75.0, < 2.0)
206
+ rubocop-ast (>= 1.44.0, < 2.0)
207
+ ruby-progressbar (1.13.0)
208
+ simplecov (0.22.0)
209
+ docile (~> 1.1)
210
+ simplecov-html (~> 0.11)
211
+ simplecov_json_formatter (~> 0.1)
212
+ simplecov-html (0.13.2)
213
+ simplecov_json_formatter (0.1.4)
214
+ sprockets (4.2.2)
215
+ concurrent-ruby (~> 1.0)
216
+ logger
217
+ rack (>= 2.2.4, < 4)
218
+ sprockets-rails (3.5.2)
219
+ actionpack (>= 6.1)
220
+ activesupport (>= 6.1)
221
+ sprockets (>= 3.0.0)
222
+ sqlite3 (1.7.3)
223
+ mini_portile2 (~> 2.8.0)
224
+ thor (1.4.0)
225
+ timeout (0.4.3)
226
+ tsort (0.2.0)
227
+ tzinfo (2.0.6)
228
+ concurrent-ruby (~> 1.0)
229
+ unicode-display_width (3.1.4)
230
+ unicode-emoji (~> 4.0, >= 4.0.4)
231
+ unicode-emoji (4.0.4)
232
+ websocket-driver (0.8.0)
233
+ base64
234
+ websocket-extensions (>= 0.1.0)
235
+ websocket-extensions (0.1.5)
236
+ zeitwerk (2.7.3)
237
+
238
+ PLATFORMS
239
+ ruby
240
+ x86_64-linux
241
+
242
+ DEPENDENCIES
243
+ bundler (~> 2.0)
244
+ json-guard!
245
+ pry (~> 0.14)
246
+ rake (~> 13.0)
247
+ rspec (~> 3.0)
248
+ rspec-rails (~> 6.0)
249
+ rubocop (~> 1.50)
250
+ rubocop-rails (~> 2.19)
251
+ simplecov (~> 0.22)
252
+ sqlite3 (~> 1.4)
253
+
254
+ BUNDLED WITH
255
+ 2.6.7
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Zaid Saeed
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 all
13
+ 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 THE
21
+ SOFTWARE.