dry_validation_parser 0.1.0 → 0.1.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: 2bad9db99d8e88991cc8c0665ebdace5ec3179688aa5caa2d3d4b0ee9170b8d1
4
- data.tar.gz: 99d855b9b749a4855c4d277ef65bd90f64470e5fde350e11d2bff6494b2a5abf
3
+ metadata.gz: 3ae5d37465ad9e23b7ff15191e76c32780ab320e3e8a0496ebeb5b51711c5ca6
4
+ data.tar.gz: 233e4b2a09271322dc5cbafc61efdec8f94ef976e5acb0f617f754cd2271435b
5
5
  SHA512:
6
- metadata.gz: d123f46e1a88ce33558a10741504938c945d53c79717f7539992657f7d3c7886cf482546011e0fe6c538d8991a75ba0c06716202aa124c5b6c7923f73ffab73c
7
- data.tar.gz: 6780789a9a14924a3323c3148b6b30b513d3996d45fe355fdc90fb62b5d432268a4aec138c85c1da86958e964034181d4c0e4bfc2b05ad272288bba362e2757b
6
+ metadata.gz: cd74a3713de2c0c7e55d46be3d36ae7d36cf95de79cbe8fed659b2c441ecf6944d6efd2778db3fa4811aabb400cd12fe3d696456f5f203c011bd1baa9e18a8b6
7
+ data.tar.gz: ec02786aefd240bbe2a455728e0ae018ce2faeda78409fe213987bd39cbda02e2653e2c77d4c44f3ea471b367ba772a67518ba2d323582d99285ca58e9796cdd
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
- :"x-nullable"=>true,
67
+ :nullable =>true,
74
68
  :type=>"string"
75
69
  }
76
70
  }
@@ -83,8 +77,6 @@ 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
 
@@ -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]][@config.nullable_type] = true
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(@config.nullable_type, false)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DryValidationParser
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  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.0
4
+ version: 0.1.1
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