dry_validation_parser 0.1.3 → 0.1.5

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: 5beb3f86e652fe9246f46a535b8ca0f69fe22cd9b928c7a06e8d1b963e4332f6
4
- data.tar.gz: 93218ef8f7b73180d4e5d808a13e8ec13ddad048764d0deaf1e024518d5846c0
3
+ metadata.gz: ccb12036211270788b640b218b3f50906ad6f8daf79c683e82b2ba4f4e9730b0
4
+ data.tar.gz: 9cf5b8d262ce584279af7b43566d148fa2ee224cc74630689ac5c824aca7b0f8
5
5
  SHA512:
6
- metadata.gz: 89cae77c9dd01b29e8595100923d212596ecf464077bda8ddb448ea749bac9b39d1fc1ed3ecc08483e74e0b44c6fc1df2fa65c848435ad20a22b7149929fe93a
7
- data.tar.gz: 370897d822e50dd27a3eb5c96c296da8fbf7ab24d02f9016a834a8b8e85dde1f5faef16ab4e1486aaf7d223b7e70f72942213506fd037b97478313a0d63b24ea
6
+ metadata.gz: 8be3fe48b53e530f316af84f4910d6a5d225b78b76de0fed4dbca1bff7435e69cf5d94ad24bd46bd98b924eff745c79aa2bb413e45c3d917b52cc3615e5d8c72
7
+ data.tar.gz: 4c118798fc0736758d95587a63098917dea8bcb5f02a8dccf799bf69619409295ed03ab120f367b6906d5b663da2877480a10f035217b3072546cc26811314ac
@@ -16,6 +16,16 @@ module DryValidationParser
16
16
  time?: "time"
17
17
  }.freeze
18
18
 
19
+ DESCRIPTION_MAPPING = {
20
+ eql?: "Must be equal to %{value}",
21
+ max_size?: "Maximum size: %{value}",
22
+ min_size?: "Minimum size: %{value}",
23
+ gteq?: "Greater than or equal to %{value}",
24
+ gt?: "Greater than %{value}",
25
+ lt?: "Lower than %{value}",
26
+ lteq?: "Lower than or equal to %{value}",
27
+ }.freeze
28
+
19
29
  # @api private
20
30
  attr_reader :keys
21
31
 
@@ -106,6 +116,22 @@ module DryValidationParser
106
116
  keys[key][:enum] += [nil] if opts.fetch(:nullable, false)
107
117
  elsif PREDICATE_TO_TYPE[name]
108
118
  keys[key][:type] = PREDICATE_TO_TYPE[name]
119
+ else
120
+ description = predicate_description(name.to_s, rest[0][1].to_s)
121
+ if keys[key][:description].to_s.empty?
122
+ keys[key][:description] = description unless description.to_s.empty?
123
+ else
124
+ keys[key][:description] += ", #{description}" unless description.to_s.empty?
125
+ end
126
+ end
127
+ end
128
+
129
+ def predicate_description(name, value)
130
+ if ::I18n.locale_available?(::I18n.locale)
131
+ ::I18n.t("contract.descriptions.#{name}", value: value, default: '')
132
+ else
133
+ description = DESCRIPTION_MAPPING[name]
134
+ description ? description % { value: 5 } : ""
109
135
  end
110
136
  end
111
137
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DryValidationParser
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "dry_validation_parser/version"
4
4
  require_relative "dry_validation_parser/validation_schema_parser"
5
+ require 'i18n'
5
6
 
6
7
  module DryValidationParser
7
8
  class Error < StandardError; end
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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane-Terziev