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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: decf43c1421bef2ac92978d38dabdec588bf7298
4
- data.tar.gz: 2b039714b4a8e8327ed02bd6d1c0905f09e89569
3
+ metadata.gz: 05684fe086ddcdacb676ba283ff540be40383e40
4
+ data.tar.gz: aea28102c9641ca140c51853cc9b3f6672eeb8da
5
5
  SHA512:
6
- metadata.gz: d2c777e8602d0db9ee867eca8ad4424f90a3eceeef21433414ff596ca7b19928f25266614fcf38ebc6101e39a6cc41e5453d8bbff34014482be916d299255283
7
- data.tar.gz: 4ef080601693d8d3e15524878ad73f68e21e4b9de2ece79f72b3d8da691485d6939ef8bd315daf893f3e062bbd0284f2ba87d3a3dac1abd7f01ea6ea7de936d8
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
@@ -1,3 +1,3 @@
1
1
  module LooseAttr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loose_attr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukuiretu