eac_rails_utils 0.17.0 → 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: 19a8c90c3c75ded82d146d46936499b9faf8f88b4573ea7cc2e3887060b26736
4
- data.tar.gz: b6989a70a22cd394da1a4e4664af735f42a1b147c12ce942534eca07d84fe669
3
+ metadata.gz: efe1c5f0500cc98440fb31e38b2ecdcf3959d5d415016ac4ad622d1a309a4695
4
+ data.tar.gz: 23e56f4eae5a1126c3136971cb84d74755aeed649f18eafc6dc10dc6118f1327
5
5
  SHA512:
6
- metadata.gz: 84cbd78c578472ef2d103818c3fdf6279ab3d77076868567e523c96d5da04c2b4cd56845d80b38c514751b01b4987807f3b811ef0c1192ec92044c9efc5ab297
7
- data.tar.gz: 712f15488d263f71cc152469a9cbf4c4f2581954502b5b9aa328e7d50a49138f76714ae1770e8b00f01e8dbbd5183151d485f92bd0bb8304c4667071152be346
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.0'
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.0
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-13 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.98'
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.98'
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
@@ -213,7 +220,6 @@ files:
213
220
  - lib/eac_rails_utils/models/test_utils.rb
214
221
  - lib/eac_rails_utils/models/validations.rb
215
222
  - lib/eac_rails_utils/patches.rb
216
- - lib/eac_rails_utils/patches/action_controller_base.rb
217
223
  - lib/eac_rails_utils/patches/active_model_associations.rb
218
224
  - lib/eac_rails_utils/patches/numeric.rb
219
225
  - lib/eac_rails_utils/patches/numeric/number_helper.rb
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'action_controller/base'
4
-
5
- module EacRailsUtils
6
- module Patches
7
- module ActionControllerBasePatch
8
- def self.included(base)
9
- base.include InstanceMethods
10
- end
11
-
12
- module InstanceMethods
13
- def redirect_back(default_path, options = {})
14
- redirect_to :back, options
15
- rescue ActionController::RedirectBackError
16
- redirect_to default_path, options
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
23
- patch = ::EacRailsUtils::Patches::ActionControllerBasePatch
24
- target = ::ActionController::Base
25
- target.send(:include, patch) unless target.included_modules.include?(patch)