You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+4-24
Original file line number
Diff line number
Diff line change
@@ -5,19 +5,9 @@
5
5
6
6
JsonValidator is an ActiveModel validator that validates any hash field against [JSONSchema](http://json-schema.org), returning errors in the model's own `errors` attribute.
7
7
8
-
## Installation
8
+
This gem was originally written to provide deep validation of JSON attributes, which are available alongside primative types in recent versions of [PostgreSQL](http://www.postgresql.org), but it works equally well with ActiveModel objects.
9
9
10
-
Add this line to your application's Gemfile:
11
-
12
-
gem 'json_validator'
13
-
14
-
And then execute:
15
-
16
-
$ bundle
17
-
18
-
Or install it yourself as:
19
-
20
-
$ gem install json_validator
10
+
Most of the functionality is dependent on the wonderful [json-schema](https://github.com/hoxworth/json-schema) gem.
21
11
22
12
## Usage
23
13
@@ -39,16 +29,6 @@ If you're using Ruby on Rails and ActiveRecord, add a validation to your model l
39
29
}
40
30
end
41
31
42
-
Then whenever an instance of `Foo` is saved, `Foo.bar` (assumed to be a hash) will be validated against the inline schema specified (eg. `Foo.new(bar: { handleSize: -10 })` would be invalid, but `Foo.new(bar: { handleSize: 10 })` would be valid).
43
-
44
-
Notes:
45
-
*`schema` can be a hash or a Proc (if you'd like to define it dynamically)
46
-
* If you're using ActiveModel without Rails the process is the same.
47
-
48
-
## Contributing
32
+
Then whenever an instance of `Foo` is saved, `Foo.bar` (assumed to be a hash) will be validated against the JSON schema specified. In this case, `Foo.new(bar: { handleSize: -10 })` would be invalid, but `Foo.new(bar: { handleSize: 10 })` would be valid.
49
33
50
-
1. Fork it ( https://github.com/[my-github-username]/json_validator/fork )
51
-
2. Create your feature branch (`git checkout -b my-new-feature`)
52
-
3. Commit your changes (`git commit -am 'Add some feature'`)
53
-
4. Push to the branch (`git push origin my-new-feature`)
54
-
5. Create a new Pull Request
34
+
The attribute being validated can be either a hash or a string (which will be parsed as JSON). The schema can be either a hash or a Proc that returns a hash (if you'd like to decide on the schema at runtime), and there's no reason why you could not load your schema from a .json file.
0 commit comments