dry_validation_parser 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -12
- data/lib/dry_validation_parser/railtie.rb +0 -4
- data/lib/dry_validation_parser/validation_schema_parser.rb +2 -3
- data/lib/dry_validation_parser/version.rb +1 -1
- data/lib/dry_validation_parser.rb +0 -2
- metadata +1 -4
- data/lib/dry_validation_parser/config/configuration.rb +0 -31
- data/lib/dry_validation_parser/config/validation_configuration.rb +0 -15
- data/lib/dry_validation_parser/tasks/configuration_generator.rake +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55534e4e0a5aba7408ed7e145abe48d5017becd36313f95ad8948af219cdfe24
|
4
|
+
data.tar.gz: 0572b97dfee11dbc4a6c0862517867abfaec77b3c5526e57b6ebf221ac47f583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19f6543ce37c88b956f5c6bfe6dfba9f8a4298b04f5a3ddc4f3a31207f53389b63bf564564e7e0d0d45adabc5e52b4f96b377712c5b2db6f9ea04871302650d6
|
7
|
+
data.tar.gz: 8ec8152ebc5579bbf37ba768269286fa41b283931b21693893c770ef1ffc7b4e675c3d0132e94f872e6f13ce9139b8a7a0ec2f20d08bea383fb3a19a171eec94
|
data/README.md
CHANGED
@@ -15,12 +15,6 @@ And then execute:
|
|
15
15
|
|
16
16
|
bundle install
|
17
17
|
|
18
|
-
After installing, execute the following command:
|
19
|
-
|
20
|
-
rake dry_validation_parser:install
|
21
|
-
|
22
|
-
This will generate configuration files in your project under `project/config/initializers`. See Configuration section for more details.
|
23
|
-
|
24
18
|
## Usage
|
25
19
|
|
26
20
|
#### Parsing a Dry::Validation::Contract
|
@@ -70,7 +64,7 @@ Lets say we have the following Dry::Validation::Contract definition:
|
|
70
64
|
:keys => {
|
71
65
|
:some_nested_attribute => {
|
72
66
|
:required => false,
|
73
|
-
:
|
67
|
+
:nullable =>true,
|
74
68
|
:type=>"string"
|
75
69
|
}
|
76
70
|
}
|
@@ -83,17 +77,12 @@ schema and generates a hash. The hash is saved in the `keys` attribute of the pa
|
|
83
77
|
The required key in our result will be set to `true` if the field is defined as
|
84
78
|
`required(:field_name)`, and `false` if defined as `optional(:field_name)`.
|
85
79
|
|
86
|
-
The "x-nullable" key depends on whether we have defined the field as value, maybe or filled.
|
87
|
-
|
88
80
|
For nested objects like array of objects or hash, we add a keys field with a definition
|
89
81
|
for each field inside the nested hash.
|
90
82
|
|
91
83
|
If the field is an array of primitive type, the type field will equal to the primitive type, and a
|
92
84
|
array flag will be set on the field.
|
93
85
|
|
94
|
-
## Custom Configuration For Your Project
|
95
|
-
You can override default configurations by changing the values in the `config/initializers/dry_validation_parser.rb` file generated from the rake command in the Installation section.
|
96
|
-
|
97
86
|
## Development
|
98
87
|
|
99
88
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -22,7 +22,6 @@ module DryValidationParser
|
|
22
22
|
# @api private
|
23
23
|
def initialize
|
24
24
|
@keys = {}
|
25
|
-
@config = Config::ValidationConfiguration
|
26
25
|
end
|
27
26
|
|
28
27
|
# @api private
|
@@ -70,7 +69,7 @@ module DryValidationParser
|
|
70
69
|
def visit_or(_, _); end
|
71
70
|
|
72
71
|
def visit_not(_node, opts = {})
|
73
|
-
keys[opts[:key]][
|
72
|
+
keys[opts[:key]][:nullable] = true
|
74
73
|
end
|
75
74
|
|
76
75
|
# @api private
|
@@ -104,7 +103,7 @@ module DryValidationParser
|
|
104
103
|
keys[key][:array] = true
|
105
104
|
elsif name.equal?(:included_in?)
|
106
105
|
keys[key][:enum] = rest[0][1]
|
107
|
-
keys[key][:enum] += [nil] if opts.fetch(
|
106
|
+
keys[key][:enum] += [nil] if opts.fetch(:nullable, false)
|
108
107
|
elsif PREDICATE_TO_TYPE[name]
|
109
108
|
keys[key][:type] = PREDICATE_TO_TYPE[name]
|
110
109
|
end
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require_relative "dry_validation_parser/version"
|
4
4
|
require_relative "dry_validation_parser/validation_schema_parser"
|
5
|
-
require_relative "dry_validation_parser/config/configuration"
|
6
|
-
require_relative "dry_validation_parser/config/validation_configuration"
|
7
5
|
require_relative "dry_validation_parser/railtie" if defined?(Rails)
|
8
6
|
|
9
7
|
module DryValidationParser
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry_validation_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jane-Terziev
|
@@ -55,10 +55,7 @@ files:
|
|
55
55
|
- README.md
|
56
56
|
- Rakefile
|
57
57
|
- lib/dry_validation_parser.rb
|
58
|
-
- lib/dry_validation_parser/config/configuration.rb
|
59
|
-
- lib/dry_validation_parser/config/validation_configuration.rb
|
60
58
|
- lib/dry_validation_parser/railtie.rb
|
61
|
-
- lib/dry_validation_parser/tasks/configuration_generator.rake
|
62
59
|
- lib/dry_validation_parser/types.rb
|
63
60
|
- lib/dry_validation_parser/validation_schema_parser.rb
|
64
61
|
- lib/dry_validation_parser/version.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DryValidationParser
|
4
|
-
module Config
|
5
|
-
module Configuration
|
6
|
-
def configuration
|
7
|
-
yield self
|
8
|
-
end
|
9
|
-
|
10
|
-
def define_setting(name, default = nil)
|
11
|
-
class_variable_set("@@#{name}", default)
|
12
|
-
|
13
|
-
define_class_method "#{name}=" do |value|
|
14
|
-
class_variable_set("@@#{name}", value)
|
15
|
-
end
|
16
|
-
|
17
|
-
define_class_method name do
|
18
|
-
class_variable_get("@@#{name}")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def define_class_method(name, &block)
|
25
|
-
(class << self; self; end).instance_eval do
|
26
|
-
define_method name, &block
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DryValidationParser
|
4
|
-
module Config
|
5
|
-
module ValidationConfiguration
|
6
|
-
extend Configuration
|
7
|
-
|
8
|
-
define_setting :enable_required_validation, true
|
9
|
-
define_setting :enable_nullable_validation, true
|
10
|
-
define_setting :enable_enums, true
|
11
|
-
define_setting :enable_descriptions, true
|
12
|
-
define_setting :nullable_type, :"x-nullable"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "fileutils"
|
4
|
-
|
5
|
-
namespace "dry_validation_parser" do
|
6
|
-
desc "Create a configuration file for Dry Validation"
|
7
|
-
task :create_configuration_file do
|
8
|
-
FileUtils.mkdir_p "#{Dir.pwd}/config/initializers/"
|
9
|
-
puts "Created #{Dir.pwd}/config/initializers/dry_validation_parser.rb"
|
10
|
-
File.open("#{Dir.pwd}/config/initializers/dry_validation_parser.rb", "w") do |file|
|
11
|
-
file.puts 'DryValidationParser::Config::ValidationConfiguration.configuration do |config|
|
12
|
-
config.enable_required_validation = true
|
13
|
-
config.enable_nullable_validation = true
|
14
|
-
config.enable_enums = true
|
15
|
-
config.enable_descriptions = true
|
16
|
-
config.nullable_type = :"x-nullable" # or :nullable
|
17
|
-
end'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
desc "Create a YAML file for Dry Validation field descriptions"
|
22
|
-
task :create_validation_descriptions_yaml do
|
23
|
-
FileUtils.mkdir_p "#{Dir.pwd}/config/locales/"
|
24
|
-
puts "Created #{Dir.pwd}/config/locales/dry_validation_parser.yml"
|
25
|
-
File.open("#{Dir.pwd}/config/locales/dry_validation_parser.yml", "w") do |file|
|
26
|
-
file.puts 'en:
|
27
|
-
validation:
|
28
|
-
descriptions:
|
29
|
-
eql?: "Must be equal to %<value>s"
|
30
|
-
max_size?: "Maximum size: %<value>s"
|
31
|
-
min_size?: "Minimum size: %<value>s"
|
32
|
-
gteq?: "Greater than or equal to %<value>s"
|
33
|
-
gt?: "Greater than %<value>s"
|
34
|
-
lt?: "Lower than %<value>s"
|
35
|
-
lteq?: "Lower than or equal to %<value>s"
|
36
|
-
'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "Creates configuration files"
|
41
|
-
task :install do
|
42
|
-
Rake::Task["dry_validation_parser:create_configuration_file"].execute
|
43
|
-
Rake::Task["dry_validation_parser:create_validation_descriptions_yaml"].execute
|
44
|
-
end
|
45
|
-
end
|