eac_rails_utils 0.17.1 → 0.17.2

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: 5db88ebd70fa8c047e4b2cd12103ff8298fbb7ebbcad0424c1b968294bb6685f
4
- data.tar.gz: 7c7b0a90c24ff1880b54f885cbeacc5ba015b28a20783ccbb3fb20f945078ad9
3
+ metadata.gz: efe1c5f0500cc98440fb31e38b2ecdcf3959d5d415016ac4ad622d1a309a4695
4
+ data.tar.gz: 23e56f4eae5a1126c3136971cb84d74755aeed649f18eafc6dc10dc6118f1327
5
5
  SHA512:
6
- metadata.gz: c8ff3b0df58c0625b4b5bfdcf09d343731790faca24071fb2cd8ae8fd56de6bdb271a8d5b057d843bb4dc43f313ae1ed6935c5369146a2c9bbdd8cd813dab3e8
7
- data.tar.gz: 8eefa5bd70d3c81a40656b3f83de88c2d1ec462b1101cc6c0952bbca5c9efa5a82f8c57438d5f2d24c37165306d9bcdf6b512211fe31b55b062b404fc2a4ba86
6
+ metadata.gz: 63ec98f3e567a68e2aa5f82d09e9fa8283861ea7d2801175f2969b13abaa126511c73a22ed7d35c5862f4a9a4c67f4553049aef96a775a4fcfae8af6e214ea13
7
+ data.tar.gz: f626434211fb0d7743fc22e6deb20fe0edc216f7ec6d425cf5514e88c1652e8b37031c4f5ebf202a41e277ca22163e7dc8012bc34c865be7d05c62d87542a286
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/yaml'
4
+
5
+ module EacRailsUtils
6
+ class YamlValidator < ActiveModel::EachValidator
7
+ DEFAULT_INVALID_YAML_MESSAGE = 'is not a valid YAML'
8
+ DEFAULT_TO_S_UNAVAILABLE_MESSAGE = 'should respond to .to_s'
9
+ DEFAULT_NOT_A_STRING_MESSAGE = '.to_s do not returned a String'
10
+
11
+ def validate_each(record, attribute, value)
12
+ return if value.blank?
13
+
14
+ string_value = stringfy_value(value)
15
+ return if string_value.nil?
16
+
17
+ return if ::EacRubyUtils::Yaml.yaml?(string_value)
18
+
19
+ record.errors[attribute] << (options[:message] || DEFAULT_INVALID_YAML_MESSAGE)
20
+ end
21
+
22
+ protected
23
+
24
+ # @param value [Object]
25
+ # @return [String, nil]
26
+ def stringfy_value(value) # rubocop:disable Metrics/AbcSize
27
+ unless value.respond_to?(:to_s)
28
+ record.errors[attribute] << (options[:message] || DEFAULT_TO_S_UNAVAILABLE_MESSAGE)
29
+ return nil
30
+ end
31
+
32
+ r = value.to_s
33
+ return r if value.is_a?(::String)
34
+
35
+ record.errors[attribute] << (options[:message] || DEFAULT_NOT_A_STRING_MESSAGE)
36
+ nil
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRailsUtils
4
- VERSION = '0.17.1'
4
+ VERSION = '0.17.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - E.A.C.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -50,14 +50,20 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.104'
53
+ version: '0.117'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.117.1
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
61
  - - "~>"
59
62
  - !ruby/object:Gem::Version
60
- version: '0.104'
63
+ version: '0.117'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.117.1
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: htmlbeautifier
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -96,16 +102,16 @@ dependencies:
96
102
  name: virtus
97
103
  requirement: !ruby/object:Gem::Requirement
98
104
  requirements:
99
- - - ">="
105
+ - - "~>"
100
106
  - !ruby/object:Gem::Version
101
- version: 1.0.5
107
+ version: '2.0'
102
108
  type: :runtime
103
109
  prerelease: false
104
110
  version_requirements: !ruby/object:Gem::Requirement
105
111
  requirements:
106
- - - ">="
112
+ - - "~>"
107
113
  - !ruby/object:Gem::Version
108
- version: 1.0.5
114
+ version: '2.0'
109
115
  - !ruby/object:Gem::Dependency
110
116
  name: nested_form_fields
111
117
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +204,7 @@ files:
198
204
  - app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
199
205
  - app/validators/eac_rails_utils/cpf_validator.rb
200
206
  - app/validators/eac_rails_utils/no_presence_validator.rb
207
+ - app/validators/eac_rails_utils/yaml_validator.rb
201
208
  - config/initializers/assets.rb
202
209
  - config/initializers/json.rb
203
210
  - config/locales/en.yml