schemacop 3.0.0.rc4 → 3.0.3
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 +4 -4
- data/CHANGELOG.md +28 -5
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/README_V3.md +14 -4
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/schemacop.rb +1 -0
- data/lib/schemacop/railtie.rb +7 -0
- data/lib/schemacop/scoped_env.rb +3 -3
- data/lib/schemacop/v3/boolean_node.rb +8 -0
- data/lib/schemacop/v3/string_node.rb +3 -0
- data/schemacop.gemspec +7 -4
- data/test/unit/schemacop/v3/boolean_node_test.rb +16 -0
- data/test/unit/schemacop/v3/string_node_test.rb +17 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8beb01b4d3fc6d20f2179d2e44086b534d50b673248635d19782fba609737ce3
|
4
|
+
data.tar.gz: e905b06d0f7bed58cf5a1247a4ec4a201fe053241516aa6269275b87ef41ba31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2418e8eacb3854f85b8fa4689d3a4819d4b6ff76aedb0910c5e7b2f41566d15339347e5890e46588f4d8859f79594bd049988d669e9c3486d4bef4db06733fa7
|
7
|
+
data.tar.gz: 26e0d958b4509fa5376703d17bc00ca05d28fc39fc631a26e2444356065e3c2f80982aa8411b89d197bccafa4a18023aaf3933221be347e1030973e8f64af5e4
|
data/CHANGELOG.md
CHANGED
@@ -10,7 +10,30 @@
|
|
10
10
|
### Changes
|
11
11
|
-->
|
12
12
|
|
13
|
-
## 3.0.
|
13
|
+
## 3.0.3 (2021-02-15)
|
14
|
+
|
15
|
+
* Fix boolean node casting
|
16
|
+
|
17
|
+
## 3.0.2 (2021-02-14)
|
18
|
+
|
19
|
+
* Fix #15 Code to ignore Zeitwerk fails when Zeitwerk is disabled
|
20
|
+
|
21
|
+
## 3.0.1 (2021-02-11)
|
22
|
+
|
23
|
+
* Add format `symbol` to strings
|
24
|
+
|
25
|
+
## 3.0.0 (2021-02-08)
|
26
|
+
|
27
|
+
* Setup Zeitwerk ignores for Rails applications
|
28
|
+
|
29
|
+
* Read previous `3.0.0.rcX` entries for all changes included
|
30
|
+
in this stable release
|
31
|
+
|
32
|
+
## 3.0.0.rc5 (2021-02-05)
|
33
|
+
|
34
|
+
* Use `ruby2_keywords` for compatibility with ruby `2.6.2`
|
35
|
+
|
36
|
+
## 3.0.0.rc4 (2021-02-02)
|
14
37
|
|
15
38
|
* Fix some minor bugs
|
16
39
|
|
@@ -19,19 +42,19 @@
|
|
19
42
|
* `used_external_schemas` for the `ReferenceNode` is now applied
|
20
43
|
recursively
|
21
44
|
|
22
|
-
## 3.0.0.rc3 (
|
45
|
+
## 3.0.0.rc3 (2021-01-28)
|
23
46
|
|
24
47
|
* Add minor improvements to the documentation
|
25
48
|
|
26
49
|
* Internal restructuring, no changes in API
|
27
50
|
|
28
|
-
## 3.0.0.rc2 (
|
51
|
+
## 3.0.0.rc2 (2021-01-28)
|
29
52
|
|
30
53
|
* Represent node names as strings internally
|
31
54
|
|
32
55
|
* Update documentation
|
33
56
|
|
34
|
-
## 3.0.0.rc1 (
|
57
|
+
## 3.0.0.rc1 (2021-01-22)
|
35
58
|
|
36
59
|
* Add support for ruby `3.0.0`
|
37
60
|
|
@@ -39,7 +62,7 @@
|
|
39
62
|
|
40
63
|
* Document all `v3` nodes
|
41
64
|
|
42
|
-
## 3.0.0.rc0 (
|
65
|
+
## 3.0.0.rc0 (2021-01-14)
|
43
66
|
|
44
67
|
* Add `Schemacop::Schema3`
|
45
68
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Schemacop is tested with the following ruby versions:
|
|
16
16
|
* 2.7.1
|
17
17
|
* 3.0.0
|
18
18
|
|
19
|
-
|
19
|
+
Other ruby versions might work but are not covered by our Travis tests.
|
20
20
|
|
21
21
|
## Basic example
|
22
22
|
|
@@ -118,4 +118,4 @@ To run tests:
|
|
118
118
|
|
119
119
|
## Copyright
|
120
120
|
|
121
|
-
Copyright
|
121
|
+
Copyright © 2016 - 2021 Sitrox. See `LICENSE` for further details.
|
data/README_V3.md
CHANGED
@@ -241,6 +241,9 @@ transformed into various types.
|
|
241
241
|
* `number`
|
242
242
|
The string must be a number and will be casted to a ruby `Float` object.
|
243
243
|
|
244
|
+
* `symbol`
|
245
|
+
The string can be anything and will be casted to a ruby `Symbol` object.
|
246
|
+
|
244
247
|
#### Examples
|
245
248
|
|
246
249
|
```ruby
|
@@ -1191,14 +1194,17 @@ local schemas > context schemas > global schemas
|
|
1191
1194
|
|
1192
1195
|
Where:
|
1193
1196
|
|
1194
|
-
* local schemas: Defined by using the DSL method
|
1197
|
+
* local schemas: Defined by using the DSL method `scm`
|
1195
1198
|
* context schemas: Defined in the current context using `context.schema`
|
1196
1199
|
* global schemas: Defined in a ruby file in the load path
|
1197
1200
|
|
1198
1201
|
### Rails applications
|
1199
1202
|
|
1200
|
-
In Rails applications, your schemas are automatically eager-
|
1201
|
-
path `'app/schemas'` when your application is started
|
1203
|
+
In Rails applications, your schemas are automatically eager-loaded from the load
|
1204
|
+
path `'app/schemas'` when your application is started, unless your application
|
1205
|
+
is running in the `DEVELOPMENT` environment. In the `DEVELOPMENT` environment,
|
1206
|
+
schemas are loaded each time when they are used, and as such you can make changes
|
1207
|
+
to your external schemas without having to restart the server each time.
|
1202
1208
|
|
1203
1209
|
After starting your application, you can reference them like normally defined
|
1204
1210
|
reference schemas, with the name being relative to the load path.
|
@@ -1246,8 +1252,12 @@ schema.validate!({usr: {first_name: 'Joe', last_name: 'Doe', groups: [{name: 'fo
|
|
1246
1252
|
### Non-Rails applications
|
1247
1253
|
|
1248
1254
|
Usage in non-Rails applications is the same as with usage in Rails applications,
|
1249
|
-
however you need to eager load the schemas yourself:
|
1255
|
+
however you might need to eager load the schemas yourself:
|
1250
1256
|
|
1251
1257
|
```ruby
|
1252
1258
|
Schemacop::V3::GlobalContext.eager_load!
|
1253
1259
|
```
|
1260
|
+
|
1261
|
+
As mentioned before, you can also use the external schemas without having to
|
1262
|
+
eager-load them, but if you use the schemas multiple times, it might be better
|
1263
|
+
to eager-load them on start of your application / script.
|
data/Rakefile
CHANGED
@@ -18,6 +18,7 @@ task :gemspec do
|
|
18
18
|
# needs access to ActiveSupport::HashWithIndifferentAccess and expects
|
19
19
|
# behavior of that as in version 5 of ActiveSupport.
|
20
20
|
spec.add_dependency 'activesupport', '>= 4.0'
|
21
|
+
spec.add_dependency 'ruby2_keywords', '0.0.4'
|
21
22
|
spec.add_development_dependency 'bundler'
|
22
23
|
spec.add_development_dependency 'rake'
|
23
24
|
spec.add_development_dependency 'minitest'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.3
|
data/lib/schemacop.rb
CHANGED
data/lib/schemacop/railtie.rb
CHANGED
@@ -5,6 +5,13 @@ module Schemacop
|
|
5
5
|
unless Rails.env.development?
|
6
6
|
V3::GlobalContext.eager_load!
|
7
7
|
end
|
8
|
+
|
9
|
+
# Tell Zeitwerk to ignore the files in our load path
|
10
|
+
if defined?(Rails) && defined?(Zeitwerk) && Rails.autoloaders.zeitwerk_enabled?
|
11
|
+
Schemacop.load_paths.each do |load_path|
|
12
|
+
Rails.autoloaders.main.ignore(Rails.root.join(load_path))
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
data/lib/schemacop/scoped_env.rb
CHANGED
@@ -7,14 +7,14 @@ module Schemacop
|
|
7
7
|
@prefix = prefix
|
8
8
|
end
|
9
9
|
|
10
|
-
def method_missing(symbol, *args,
|
10
|
+
ruby2_keywords def method_missing(symbol, *args, &block)
|
11
11
|
symbol = :"#{@prefix}#{symbol}" if @prefix
|
12
12
|
|
13
13
|
if @methods.include?(symbol)
|
14
14
|
if @delegation_object.respond_to?(symbol)
|
15
|
-
@delegation_object.send(symbol, *args,
|
15
|
+
@delegation_object.send(symbol, *args, &block)
|
16
16
|
elsif @backup_binding.respond_to?(symbol)
|
17
|
-
@backup_binding.send(symbol, *args,
|
17
|
+
@backup_binding.send(symbol, *args, &block)
|
18
18
|
else
|
19
19
|
super
|
20
20
|
end
|
@@ -16,6 +16,7 @@ module Schemacop
|
|
16
16
|
email: URI::MailTo::EMAIL_REGEXP,
|
17
17
|
boolean: /^(true|false)$/,
|
18
18
|
binary: nil,
|
19
|
+
symbol: nil,
|
19
20
|
integer: /^-?[0-9]+$/,
|
20
21
|
number: /^-?[0-9]+(\.[0-9]+)?$/
|
21
22
|
}.freeze
|
@@ -87,6 +88,8 @@ module Schemacop
|
|
87
88
|
return Integer(to_cast)
|
88
89
|
when :number
|
89
90
|
return Float(to_cast)
|
91
|
+
when :symbol
|
92
|
+
return to_cast.to_sym
|
90
93
|
else
|
91
94
|
return to_cast
|
92
95
|
end
|
data/schemacop.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.
|
2
|
+
# stub: schemacop 3.0.3 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "schemacop".freeze
|
6
|
-
s.version = "3.0.
|
6
|
+
s.version = "3.0.3"
|
7
7
|
|
8
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Sitrox".freeze]
|
11
|
-
s.date = "2021-02-
|
11
|
+
s.date = "2021-02-15"
|
12
12
|
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/validator/array_validator.rb".freeze, "lib/schemacop/v2/validator/boolean_validator.rb".freeze, "lib/schemacop/v2/validator/float_validator.rb".freeze, "lib/schemacop/v2/validator/hash_validator.rb".freeze, "lib/schemacop/v2/validator/integer_validator.rb".freeze, "lib/schemacop/v2/validator/nil_validator.rb".freeze, "lib/schemacop/v2/validator/number_validator.rb".freeze, "lib/schemacop/v2/validator/object_validator.rb".freeze, "lib/schemacop/v2/validator/string_validator.rb".freeze, "lib/schemacop/v2/validator/symbol_validator.rb".freeze, "lib/schemacop/v3.rb".freeze, "lib/schemacop/v3/all_of_node.rb".freeze, "lib/schemacop/v3/any_of_node.rb".freeze, "lib/schemacop/v3/array_node.rb".freeze, "lib/schemacop/v3/boolean_node.rb".freeze, "lib/schemacop/v3/combination_node.rb".freeze, "lib/schemacop/v3/context.rb".freeze, "lib/schemacop/v3/dsl_scope.rb".freeze, "lib/schemacop/v3/global_context.rb".freeze, "lib/schemacop/v3/hash_node.rb".freeze, "lib/schemacop/v3/integer_node.rb".freeze, "lib/schemacop/v3/is_not_node.rb".freeze, "lib/schemacop/v3/node.rb".freeze, "lib/schemacop/v3/node_registry.rb".freeze, "lib/schemacop/v3/number_node.rb".freeze, "lib/schemacop/v3/numeric_node.rb".freeze, "lib/schemacop/v3/object_node.rb".freeze, "lib/schemacop/v3/one_of_node.rb".freeze, "lib/schemacop/v3/reference_node.rb".freeze, "lib/schemacop/v3/result.rb".freeze, "lib/schemacop/v3/string_node.rb".freeze, "lib/schemacop/v3/symbol_node.rb".freeze, "schemacop.gemspec".freeze, "test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
|
13
13
|
s.homepage = "https://github.com/sitrox/schemacop".freeze
|
14
14
|
s.licenses = ["MIT".freeze]
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
23
|
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
24
|
+
s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
24
25
|
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
25
26
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
26
27
|
s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
|
@@ -32,6 +33,7 @@ Gem::Specification.new do |s|
|
|
32
33
|
s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
|
33
34
|
else
|
34
35
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
36
|
+
s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
35
37
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
36
38
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
37
39
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
@@ -44,6 +46,7 @@ Gem::Specification.new do |s|
|
|
44
46
|
end
|
45
47
|
else
|
46
48
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
49
|
+
s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
47
50
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
48
51
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
49
52
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
@@ -120,6 +120,22 @@ module Schemacop
|
|
120
120
|
]
|
121
121
|
})
|
122
122
|
end
|
123
|
+
|
124
|
+
def test_cast
|
125
|
+
schema :boolean
|
126
|
+
|
127
|
+
assert_cast(true, true)
|
128
|
+
assert_cast(false, false)
|
129
|
+
assert_cast(nil, nil)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_cast_default
|
133
|
+
schema :boolean, default: true
|
134
|
+
|
135
|
+
assert_cast(true, true)
|
136
|
+
assert_cast(false, false)
|
137
|
+
assert_cast(nil, true)
|
138
|
+
end
|
123
139
|
end
|
124
140
|
end
|
125
141
|
end
|
@@ -165,6 +165,23 @@ module Schemacop
|
|
165
165
|
assert_cast('john.doe@example.com', 'john.doe@example.com')
|
166
166
|
end
|
167
167
|
|
168
|
+
def test_format_symbol
|
169
|
+
schema :string, format: :symbol
|
170
|
+
|
171
|
+
assert_json(type: :string, format: :symbol)
|
172
|
+
|
173
|
+
assert_validation 'foobar'
|
174
|
+
assert_validation ''
|
175
|
+
|
176
|
+
assert_validation 234 do
|
177
|
+
error '/', 'Invalid type, expected "string".'
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_cast(nil, nil)
|
181
|
+
assert_cast('foobar', :foobar)
|
182
|
+
assert_cast('039n23$g- sfk3/', :'039n23$g- sfk3/')
|
183
|
+
end
|
184
|
+
|
168
185
|
def test_enum
|
169
186
|
schema :string, enum: ['foo', 'some string', 'some other string', 42]
|
170
187
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemacop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby2_keywords
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,9 +288,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
288
|
version: '0'
|
275
289
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
290
|
requirements:
|
277
|
-
- - "
|
291
|
+
- - ">="
|
278
292
|
- !ruby/object:Gem::Version
|
279
|
-
version:
|
293
|
+
version: '0'
|
280
294
|
requirements: []
|
281
295
|
rubygems_version: 3.0.3
|
282
296
|
signing_key:
|