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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d86e0bb1622e18a077148963bb1ae3eb20a8f18bae5a09369fcd16906e7282e
4
- data.tar.gz: b224c6aa601aadaea6120d6c4d4f93fc642bc7f810398552b4b5fb109a004c56
3
+ metadata.gz: 6527474ebab74c59a61f0898d23b4716445fca7bf697a49ef3f73995ec38537f
4
+ data.tar.gz: ed6e6c8a5de426d0849ef362c08c1120d102da93e9f36e9f63dc88ddefaf1c15
5
5
  SHA512:
6
- metadata.gz: eb39073129a26732553f4687e8039cf1f4e003548333bc63c24df60791289f98476e199b909019ca87fcb494aad40eacc2784a047e73e99704b807a05dbe0c9f
7
- data.tar.gz: d2a42ddc1bfd46b815080aeb07b134352795fb32816d6c4c3ab7961b100e479108804811d84a31fe7d42b6d3000612d1f723ab9ae552b45e73f2917336cc44c2
6
+ metadata.gz: 6f477282a5d99cbd20d957183c0cd0448943923e1662220b670b6fcecb2519a469e4152c7fdabe73c741d6fdee6ae5708be16c1722c8b81685874a337ef75df3
7
+ data.tar.gz: c640421b0903242a1deab3431408000e39afa8db8ea2b0bf307e6470654382c15379f768836488bf1c0d5d2ee686dac95dbf0ce1f6539ad07d66546759d7b4af
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 1.7.0
6
+ - ActiveRecord/ActiveModel type cast : refactor + add date + add boolean
7
+
5
8
  ## 1.6.2
6
9
  - Fix cucumber/capybara helpers
7
10
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  require_relative "active_model_custom_error_messages"
2
- require_relative "active_record_comma_type_cast"
2
+ require_relative "active_model_type_cast"
3
3
  require_relative "form_back_url"
@@ -1,3 +1,3 @@
1
1
  module Agilibox
2
- VERSION = "1.6.2"
2
+ VERSION = "1.7.0"
3
3
  end
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.6.2
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-17 00:00:00.000000000 Z
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/active_record_comma_type_cast.rb
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)