hellobase-formtastic 0.4.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: 91ed20f61e12cb7e7f2ae092cd5bb50bc1046e67e1ea1951e9f5c34cae10f438
4
- data.tar.gz: 8622f461fbe818499fe85bde5fb22561f8a9ecddd3c86d3e15b5ca32946cb247
3
+ metadata.gz: '089f5fd3bc31975a859b2201261dd68fd82929873f6064f47141850891e2fcb2'
4
+ data.tar.gz: 25baf9a20b79540f15b5993844c0a8ac5ceb82c4b04f4ad7d6f212c764281acd
5
5
  SHA512:
6
- metadata.gz: a47ca291dfc839b4884d42180c840b5adb03931a7213e16198280ae518710f5ef6d243d83f4d8fb2f5b913bd943975528385cd5b518fb7c2f9d2b6375e76e994
7
- data.tar.gz: 1ed1b99f2dc90f92361732e65c9f38d2b7043ff2ddb7990ff4bba6751272213db762c58f62a5eb1309afe70bad02187fc9ef57704314a9f240080f04bf1dd537
6
+ metadata.gz: 9397a0119c1744d71906d99aab2d07c4771917cea709cc50df072e5dd19e9305ec2d0e26e9b62e417497038487477c486df325fe005cf35d6b7fd271b9c4751a
7
+ data.tar.gz: 6101d0b598d27b62203151b1eaf6ad6a6b427d66072ff787e5b193dc7d98cda64337f4a2769d3dbeafc777859033127f1b59abcba78ee89e4c41eeb6eca2eb85
@@ -13,41 +13,55 @@ 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
- val = if ivars.any? {|v| !instance_variable_defined?(v) || instance_variable_get(v).blank? }
58
+ define_method recalc_method do
59
+ val = if attrs.any? {|attr| send(attr).blank? }
46
60
  nil
47
61
  else
48
62
  begin
49
- Time.use_zone(instance_variable_get(ivars[3])) do
50
- Time.parse("#{instance_variable_get(ivars[0])} #{instance_variable_get(ivars[1])}:#{instance_variable_get(ivars[2])}")
63
+ Time.use_zone(send(attrs[3])) do
64
+ Time.zone.parse("#{send(attrs[0])} #{send(attrs[1])}:#{send(attrs[2])}")
51
65
  end
52
66
  rescue ArgumentError
53
67
  nil
@@ -57,7 +71,7 @@ module Hellobase
57
71
  send :"#{base}=", val
58
72
  end
59
73
 
60
- private method
74
+ private recalc_method
61
75
  end
62
76
  end
63
77
 
@@ -1,5 +1,5 @@
1
1
  module Hellobase
2
2
  module Formtastic
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellobase-formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Wang