loose_attr 0.0.2 → 0.0.3
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 +4 -4
- data/lib/loose_attr/active_record_ext.rb +5 -3
- data/lib/loose_attr/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05684fe086ddcdacb676ba283ff540be40383e40
|
4
|
+
data.tar.gz: aea28102c9641ca140c51853cc9b3f6672eeb8da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cee17ce7ef245b88010da1d287563098a96893a9322e46c8bc0b46bedf41c8fad197705e7bcb6f956d338eb62db05e13a7dff8b25e8d409aecf640ef78dc847a
|
7
|
+
data.tar.gz: b9b3b08543162c4d336ca82adb64316009f2d5e0e9ccd4d83b448fa3fea6d10845979f913a4e295307297b951e81a00e3d888cb38f098e6b480919d235416c54
|
@@ -9,11 +9,11 @@ module LooseAttr
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
def loose_attr(name, cast_type: :string, default_value: nil)
|
12
|
+
def loose_attr(name, cast_type: :string, default_value: nil, option: {})
|
13
13
|
# read attr
|
14
14
|
define_method name do
|
15
15
|
value = hashed_ext.send(name.to_s) || default_value
|
16
|
-
cast(value, cast_type)
|
16
|
+
cast(value, cast_type, option)
|
17
17
|
end
|
18
18
|
|
19
19
|
# write attr
|
@@ -46,7 +46,7 @@ module LooseAttr
|
|
46
46
|
@hashed_ext = ::Hashie::Mash.new(JSON.parse(ext_field)) if ext_field.present?
|
47
47
|
end
|
48
48
|
|
49
|
-
def cast(value, cast_type)
|
49
|
+
def cast(value, cast_type, option)
|
50
50
|
return nil if value.blank?
|
51
51
|
|
52
52
|
case cast_type
|
@@ -56,6 +56,8 @@ module LooseAttr
|
|
56
56
|
value.to_i
|
57
57
|
when :boolean
|
58
58
|
value.to_b
|
59
|
+
when :date
|
60
|
+
DateTime.strptime(value, option[:format]).in_time_zone
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
data/lib/loose_attr/version.rb
CHANGED