hellobase-formtastic 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23204b79fccf4dbacbe9826a220766e0604923a959673771c8fc38bc6240997e
4
- data.tar.gz: f13d31c76387f8646d180dcf65482b85c38cf742de6297b4dcb07a1b0b4fe5a3
3
+ metadata.gz: '089f5fd3bc31975a859b2201261dd68fd82929873f6064f47141850891e2fcb2'
4
+ data.tar.gz: 25baf9a20b79540f15b5993844c0a8ac5ceb82c4b04f4ad7d6f212c764281acd
5
5
  SHA512:
6
- metadata.gz: d9561afc8619c56078637790305dc024d0a19e39e58a4b25942ae76ef3a09cd434c1bbe8d3389068dc276709254d1a79fa820973ab911cdc65bfb0318a31a5b8
7
- data.tar.gz: 2e5725f7722d104c5ddecdb173614b7457338eb2030802521045842dcea08adcbaac3c27062bf4dcb2fc49b55040d231624712a9fa0e9d5206aad33393738498
6
+ metadata.gz: 9397a0119c1744d71906d99aab2d07c4771917cea709cc50df072e5dd19e9305ec2d0e26e9b62e417497038487477c486df325fe005cf35d6b7fd271b9c4751a
7
+ data.tar.gz: 6101d0b598d27b62203151b1eaf6ad6a6b427d66072ff787e5b193dc7d98cda64337f4a2769d3dbeafc777859033127f1b59abcba78ee89e4c41eeb6eca2eb85
@@ -13,49 +13,65 @@ module Hellobase
13
13
  def self.define_virtual_attributes(klass, base)
14
14
  attrs = virtual_attributes(base)
15
15
  ivars = attrs.map {|a| :"@#{a}" }
16
- method = :"_dpwt_set_#{base}"
16
+ recalc_method = :"_dpwt_recalc_#{base}"
17
17
 
18
18
  klass.class_eval do
19
19
  define_method attrs[0] do
20
- send(base)&.strftime('%Y-%m-%d')
20
+ if instance_variable_defined? ivars[0]
21
+ instance_variable_get ivars[0]
22
+ else
23
+ instance_variable_set ivars[0], send(base)&.strftime('%Y-%m-%d')
24
+ end
21
25
  end
22
26
 
23
27
  define_method attrs[1] do
24
- send(base)&.strftime('%H')
28
+ if instance_variable_defined? ivars[1]
29
+ instance_variable_get ivars[1]
30
+ else
31
+ instance_variable_set ivars[1], send(base)&.strftime('%H')
32
+ end
25
33
  end
26
34
 
27
35
  define_method attrs[2] do
28
- send(base)&.strftime('%M')
36
+ if instance_variable_defined? ivars[2]
37
+ instance_variable_get ivars[2]
38
+ else
39
+ instance_variable_set ivars[2], send(base)&.strftime('%M')
40
+ end
29
41
  end
30
42
 
31
43
  define_method attrs[3] do
32
- send(base)&.strftime('%Z')
44
+ if instance_variable_defined? ivars[3]
45
+ instance_variable_get ivars[3]
46
+ else
47
+ instance_variable_set ivars[3], send(base)&.zone
48
+ end
33
49
  end
34
50
 
35
51
  attrs.each_with_index do |a, i|
36
52
  define_method :"#{a}=" do |val|
37
53
  instance_variable_set ivars[i], val
38
- send(method)
39
-
40
- val
54
+ send recalc_method
41
55
  end
42
56
  end
43
57
 
44
- define_method method do
45
- send :"#{base}=",
46
- ivars.any? {|v| instance_variable_get(v).blank? } ?
47
- nil :
48
- [
49
- instance_variable_get(ivars[0]),
50
- [
51
- instance_variable_get(ivars[1]),
52
- instance_variable_get(ivars[2])
53
- ].join(':'),
54
- instance_variable_get(ivars[3]),
55
- ].join(' ')
58
+ define_method recalc_method do
59
+ val = if attrs.any? {|attr| send(attr).blank? }
60
+ nil
61
+ else
62
+ begin
63
+ Time.use_zone(send(attrs[3])) do
64
+ Time.zone.parse("#{send(attrs[0])} #{send(attrs[1])}:#{send(attrs[2])}")
65
+ end
66
+ rescue ArgumentError
67
+ nil
68
+ end
69
+ end
70
+
71
+ send :"#{base}=", val
56
72
  end
57
73
 
58
- private method
74
+ private recalc_method
59
75
  end
60
76
  end
61
77
 
@@ -1,5 +1,5 @@
1
1
  module Hellobase
2
2
  module Formtastic
3
- VERSION = '0.3.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellobase-formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-19 00:00:00.000000000 Z
11
+ date: 2025-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin