schemacop 3.0.0.rc5 → 3.0.4

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: 7fdf2a714534a94acf7c83e028fe7ce1e4b62c76266cc3e01786cd408d5c17c9
4
- data.tar.gz: 21ba336e330bf881d4f99cb63c4070dea7559813d7387faa0a2ee53c85fdbb1e
3
+ metadata.gz: 2b28a407ae498b94fa8c7897895d052c1bea34ebeee991ab992b4a86aa94f7ab
4
+ data.tar.gz: 7bd4dbd4f0a51ac591a7ff6189fd98e803597c0487f8a16e43c78774dc75c5e3
5
5
  SHA512:
6
- metadata.gz: 3636130ba0c0ee471e97e3ef9e259cc86840eaaf6b6435466fcaa17dafdb17aaff406b052e7e3eeffbbbb6e0f1fe3283feb5dda4dfcd5a008d3d60ee8c01f5bf
7
- data.tar.gz: 46fa1c3b015cfa725e9c624f74fc16f0bf07c6db64e74282e12136c17dc664ae02edb128fe3110516728fab47c2fd105068fb2d9b318f617db39f82dc6264b64
6
+ metadata.gz: b40fb214b50815f65f87f978052f0c6bc38018340d00eeeddb68e392dfb44106e0d6ebeb5e908172113dadc57cd0f88bbdf1d230d38cd5dab31382f8d217f34a
7
+ data.tar.gz: cf87908ded44c22bd53b824e732f7447ade01608104cb55a844879fb7f17b2172b78c13b47adb0f373abbba3a90f75d353cf0f63ec5d74b16128eee780743db6
data/CHANGELOG.md CHANGED
@@ -10,6 +10,30 @@
10
10
  ### Changes
11
11
  -->
12
12
 
13
+ ## 3.0.4 (2021-02-15)
14
+
15
+ * Add `examples_keyword` to context which allows to customize the name of the
16
+ `examples` attribute in JSON output
17
+
18
+ ## 3.0.3 (2021-02-15)
19
+
20
+ * Fix boolean node casting
21
+
22
+ ## 3.0.2 (2021-02-14)
23
+
24
+ * Fix #15 Code to ignore Zeitwerk fails when Zeitwerk is disabled
25
+
26
+ ## 3.0.1 (2021-02-11)
27
+
28
+ * Add format `symbol` to strings
29
+
30
+ ## 3.0.0 (2021-02-08)
31
+
32
+ * Setup Zeitwerk ignores for Rails applications
33
+
34
+ * Read previous `3.0.0.rcX` entries for all changes included
35
+ in this stable release
36
+
13
37
  ## 3.0.0.rc5 (2021-02-05)
14
38
 
15
39
  * Use `ruby2_keywords` for compatibility with ruby `2.6.2`
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Sitrox
3
+ Copyright © 2016 - 2021 Sitrox
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- For these versions, the automated CI tests are ran on travis. Other ruby versions might work, but stick to these versions for best results.
19
+ Other ruby versions might work but are not covered by our Travis tests.
20
20
 
21
21
  ## Basic example
22
22
 
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? `scm`
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-laoded from the load
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/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0.rc5
1
+ 3.0.4
@@ -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
@@ -11,6 +11,14 @@ module Schemacop
11
11
  FalseClass => :boolean
12
12
  }
13
13
  end
14
+
15
+ def cast(value)
16
+ if value.is_a?(TrueClass) || value.is_a?(FalseClass)
17
+ value
18
+ else
19
+ default
20
+ end
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -2,9 +2,13 @@ module Schemacop
2
2
  module V3
3
3
  class Context
4
4
  attr_accessor :schemas
5
+ attr_accessor :examples_keyword
6
+
7
+ DEFAULT_EXAMPLES_KEYWORD = :examples
5
8
 
6
9
  def initialize
7
10
  @schemas = {}.with_indifferent_access.freeze
11
+ @examples_keyword = DEFAULT_EXAMPLES_KEYWORD
8
12
  end
9
13
 
10
14
  def schema(name, type = :hash, **options, &block)
@@ -170,7 +170,7 @@ module Schemacop
170
170
  end
171
171
 
172
172
  json[:title] = @title if @title
173
- json[:examples] = @examples if @examples
173
+ json[Schemacop.context.examples_keyword] = @examples if @examples
174
174
  json[:description] = @description if @description
175
175
  json[:default] = @default if @default
176
176
  json[:enum] = @enum.to_a if @enum
@@ -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.0.rc5 ruby lib
2
+ # stub: schemacop 3.0.4 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.0.rc5"
6
+ s.version = "3.0.4"
7
7
 
8
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1".freeze) if s.respond_to? :required_rubygems_version=
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-05"
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]
@@ -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.0.rc5
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,8 +164,8 @@ dependencies:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.21.2
167
- description:
168
- email:
167
+ description:
168
+ email:
169
169
  executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
@@ -277,7 +277,7 @@ homepage: https://github.com/sitrox/schemacop
277
277
  licenses:
278
278
  - MIT
279
279
  metadata: {}
280
- post_install_message:
280
+ post_install_message:
281
281
  rdoc_options: []
282
282
  require_paths:
283
283
  - lib
@@ -288,12 +288,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
288
288
  version: '0'
289
289
  required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  requirements:
291
- - - ">"
291
+ - - ">="
292
292
  - !ruby/object:Gem::Version
293
- version: 1.3.1
293
+ version: '0'
294
294
  requirements: []
295
- rubygems_version: 3.0.3
296
- signing_key:
295
+ rubygems_version: 3.1.4
296
+ signing_key:
297
297
  specification_version: 4
298
298
  summary: Schemacop validates ruby structures consisting of nested hashes and arrays
299
299
  against simple schema definitions.