eac_rails_utils 0.17.1 → 0.18.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69ab406dd1dd999da6a2fdefa92e15ad6c1a2faeb14f0474fa7fd20938a71ef
|
4
|
+
data.tar.gz: f91fdd425c80747f432acbcdd4ed80c399eed2e80f3d1e862699dbb0839d9077
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f772b792fb6684dfff2e450286e5f014d04e4b9c45630a8cc7d3486c9a70cb895381ba4480e973a4b2cdc4cde5a29bfa94392c8e2efc9e141a08e2ce0e126d4
|
7
|
+
data.tar.gz: 2a5cc246cb003b694e2701bb70409cc7df7e2e69fc80d093a47912dbed5d50c2e1cdab740e4e9d36f29469cc84fd8bc83a50fd15f66cbda35b4ecd328093139a
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRailsUtils
|
4
|
+
class ImmutableValidator < ActiveModel::EachValidator
|
5
|
+
DEFAULT_MESSAGE = 'cannot be changed'
|
6
|
+
|
7
|
+
def validate_each(record, attribute, _value)
|
8
|
+
return if record.new_record?
|
9
|
+
return unless record.send("#{attribute}_changed?")
|
10
|
+
|
11
|
+
record.errors[attribute] << (options[:message] || DEFAULT_MESSAGE)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -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
|
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.
|
4
|
+
version: 0.18.0
|
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:
|
11
|
+
date: 2023-05-30 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.
|
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.
|
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:
|
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:
|
114
|
+
version: '2.0'
|
109
115
|
- !ruby/object:Gem::Dependency
|
110
116
|
name: nested_form_fields
|
111
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,7 +203,9 @@ files:
|
|
197
203
|
- app/helpers/eac_rails_utils/menus_helper/gui_builder.rb
|
198
204
|
- app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
|
199
205
|
- app/validators/eac_rails_utils/cpf_validator.rb
|
206
|
+
- app/validators/eac_rails_utils/immutable_validator.rb
|
200
207
|
- app/validators/eac_rails_utils/no_presence_validator.rb
|
208
|
+
- app/validators/eac_rails_utils/yaml_validator.rb
|
201
209
|
- config/initializers/assets.rb
|
202
210
|
- config/initializers/json.rb
|
203
211
|
- config/locales/en.yml
|