activerecord_json_validator 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f5b518bda8ab28520f561dc840f47223e252530a9182ef31a164c12fb831451
4
- data.tar.gz: 79e01fcce3c8cb0e27f6e3e24df4db54a312f6cef7285f38cec05689e897d042
3
+ metadata.gz: a23791df42cc3761bf97c7582c7ba526806b2b163708e5bf1fe8250b6236d067
4
+ data.tar.gz: 57f080ea733883b1e83e81ed28bc28d17332b8939699a3f48cfca9ef49689ffe
5
5
  SHA512:
6
- metadata.gz: b4e5420f0c6aaad0e1e13ed296bc598e88b16974bfbaa7e55cc1680ad4ca499ba0b570de3ee26d72a993cbb9e712370f7e23fcf14e56e46ba40d7c601c5695f1
7
- data.tar.gz: 93cf5acde18b71f512f2f68eaec1ba8191a721e1ace7853604d9e6ac4c6c7d03ae88a19c402a4c8b8545e8bfa5546de4ced97dfa032536f18747a5658419b752
6
+ metadata.gz: 53836d631662e35b1e864379491a11fbebfde8207318dde0a2572f83d22811add057b5f35609f4bc267e17b0d16aa3672b8e057521ec2f797d9b160cceae0b9a
7
+ data.tar.gz: f8806eaa64ee2bb70ff2d44a91f53b8bc2c068b26eb38138f0fd600417263b138d0f5f61f35d0d08457583129260d11bcf8f54761ae4e5fd5996885988b08472
data/README.md CHANGED
@@ -16,16 +16,17 @@
16
16
  Add this line to your application's Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'activerecord_json_validator'
19
+ gem 'activerecord_json_validator', '~> 2.0.0'
20
20
  ```
21
21
 
22
22
  ## Usage
23
23
 
24
24
  ### JSON Schema
25
- Schemas must use be a JSON string or use string keys.
25
+
26
+ Schemas should be a JSON file
26
27
 
27
28
  ```json
28
- '{
29
+ {
29
30
  "type": "object",
30
31
  "$schema": "http://json-schema.org/draft-04/schema#",
31
32
  "properties": {
@@ -33,20 +34,6 @@ Schemas must use be a JSON string or use string keys.
33
34
  "country": { "type": "string" }
34
35
  },
35
36
  "required": ["country"]
36
- }'
37
- ```
38
-
39
- or
40
-
41
- ```ruby
42
- {
43
- "type" => "object",
44
- "$schema" => "http://json-schema.org/draft-04/schema#",
45
- "properties" => {
46
- "city" => { "type" => "string" },
47
- "country" => { "type" => "string" }
48
- },
49
- "required" => ["country"]
50
37
  }
51
38
  ```
52
39
 
@@ -60,7 +47,7 @@ end
60
47
 
61
48
  class User < ActiveRecord::Base
62
49
  # Constants
63
- PROFILE_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile.json_schema').to_s
50
+ PROFILE_JSON_SCHEMA = Pathname.new(Rails.root.join('config', 'schemas', 'profile.json'))
64
51
 
65
52
  # Validations
66
53
  validates :name, presence: true
@@ -80,16 +67,16 @@ user.profile_invalid_json # => '{invalid JSON":}'
80
67
 
81
68
  #### Options
82
69
 
83
- | Option | Description
84
- |------------|-----------------------------------------------------
85
- | `:schema` | The JSON schema to validate the data against (see **Schema** section)
86
- | `:message` | The ActiveRecord message added to the record errors (see **Message** section)
87
- | `:options` | A `Hash` of [`json_schemer`](https://github.com/davishmcclurg/json_schemer#options)-supported options to pass to the validator
70
+ | Option | Description |
71
+ | ---------- | ------------------------------------------------------------------------------------------------------------------------------ |
72
+ | `:schema` | The JSON schema to validate the data against (see **Schema** section) |
73
+ | `:message` | The ActiveRecord message added to the record errors (see **Message** section) |
74
+ | `:options` | A `Hash` of [`json_schemer`](https://github.com/davishmcclurg/json_schemer#options)-supported options to pass to the validator |
88
75
 
89
76
  ##### Schema
90
77
 
91
78
  `ActiveRecord::JSONValidator` uses the [json_schemer](https://github.com/davishmcclurg/json_schemer) gem to validate the JSON
92
- data against a JSON schema.
79
+ data against a JSON schema.
93
80
 
94
81
  Additionally, you can use a `Symbol` or a `Proc`. Both will be executed in the
95
82
  context of the validated record (`Symbol` will be sent as a method and the
@@ -136,7 +123,7 @@ user.errors.full_messages
136
123
 
137
124
  ## License
138
125
 
139
- `ActiveRecord::JSONValidator` is © 2013-2016 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/activerecord_json_validator/blob/master/LICENSE.md) file.
126
+ `ActiveRecord::JSONValidator` is © 2013-2016 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/activerecord_json_validator/blob/master/LICENSE.md) file.
140
127
 
141
128
  The tree logo is based on [this lovely icon](http://thenounproject.com/term/tree/51004/) by [Sara Quintana](http://thenounproject.com/sara.quintana.75), from The Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
142
129
 
@@ -15,7 +15,7 @@ class JsonValidator < ActiveModel::EachValidator
15
15
  # Validate the JSON value with a JSON schema path or String
16
16
  def validate_each(record, attribute, value)
17
17
  # Validate value with JSON Schemer
18
- errors = JSONSchemer.schema(schema(record), options.fetch(:options)).validate(value).to_a
18
+ errors = JSONSchemer.schema(schema(record), **options.fetch(:options)).validate(value).to_a
19
19
 
20
20
  # Everything is good if we don’t have any errors and we got valid JSON value
21
21
  return if errors.empty? && record.send(:"#{attribute}_invalid_json").blank?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module JSONValidator
5
- VERSION = '2.0.0'
5
+ VERSION = '2.0.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_json_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler