agilibox 1.6.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/agilibox/active_model_type_cast.rb +52 -0
- data/lib/agilibox/core_and_rails_ext.rb +1 -1
- data/lib/agilibox/version.rb +1 -1
- metadata +3 -3
- data/lib/agilibox/active_record_comma_type_cast.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6527474ebab74c59a61f0898d23b4716445fca7bf697a49ef3f73995ec38537f
|
4
|
+
data.tar.gz: ed6e6c8a5de426d0849ef362c08c1120d102da93e9f36e9f63dc88ddefaf1c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f477282a5d99cbd20d957183c0cd0448943923e1662220b670b6fcecb2519a469e4152c7fdabe73c741d6fdee6ae5708be16c1722c8b81685874a337ef75df3
|
7
|
+
data.tar.gz: c640421b0903242a1deab3431408000e39afa8db8ea2b0bf307e6470654382c15379f768836488bf1c0d5d2ee686dac95dbf0ce1f6539ad07d66546759d7b4af
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Agilibox::ActiveModelTypeCast
|
2
|
+
module Decimal
|
3
|
+
def cast_value(value)
|
4
|
+
if value.is_a?(String)
|
5
|
+
super value.tr(",", ".").gsub(/[^-0-9\.]/, "")
|
6
|
+
else
|
7
|
+
super value
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Date
|
13
|
+
# rubocop:disable Style/RegexpLiteral
|
14
|
+
SANITIZABLE_FORMATS = [
|
15
|
+
/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/,
|
16
|
+
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/,
|
17
|
+
]
|
18
|
+
# rubocop:enable Style/RegexpLiteral
|
19
|
+
|
20
|
+
def cast_value(value)
|
21
|
+
if sanitizable?(value)
|
22
|
+
super sanitize(value)
|
23
|
+
else
|
24
|
+
super value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def sanitize(value)
|
31
|
+
value.delete(" ")
|
32
|
+
end
|
33
|
+
|
34
|
+
def sanitizable?(value)
|
35
|
+
return false unless value.is_a?(String)
|
36
|
+
sanitized = sanitize(value)
|
37
|
+
SANITIZABLE_FORMATS.any? { |r| r =~ sanitized }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Boolean
|
42
|
+
def cast_value(value)
|
43
|
+
value = value.strip if value.is_a?(String)
|
44
|
+
super value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
ActiveModel::Type::Date.send(:prepend, Agilibox::ActiveModelTypeCast::Date)
|
50
|
+
ActiveModel::Type::Boolean.send(:prepend, Agilibox::ActiveModelTypeCast::Boolean)
|
51
|
+
ActiveModel::Type::Decimal.send(:prepend, Agilibox::ActiveModelTypeCast::Decimal)
|
52
|
+
ActiveModel::Type::Float.send(:prepend, Agilibox::ActiveModelTypeCast::Decimal)
|
data/lib/agilibox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agilibox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agilidée
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails-i18n
|
@@ -165,7 +165,7 @@ files:
|
|
165
165
|
- db/migrate/20000101000000_enable_agilibox_extensions.rb
|
166
166
|
- lib/agilibox.rb
|
167
167
|
- lib/agilibox/active_model_custom_error_messages.rb
|
168
|
-
- lib/agilibox/
|
168
|
+
- lib/agilibox/active_model_type_cast.rb
|
169
169
|
- lib/agilibox/config.rb
|
170
170
|
- lib/agilibox/core_and_rails_ext.rb
|
171
171
|
- lib/agilibox/cucumber_config.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Agilibox::ActiveRecordCommaTypeCast
|
2
|
-
def cast_value(value)
|
3
|
-
if value.is_a?(String)
|
4
|
-
super value.tr(",", ".").gsub(/[^-0-9\.]/, "")
|
5
|
-
else
|
6
|
-
super value
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
ActiveRecord::Type::Decimal.send(:prepend, Agilibox::ActiveRecordCommaTypeCast)
|
12
|
-
ActiveRecord::Type::Float.send(:prepend, Agilibox::ActiveRecordCommaTypeCast)
|