attr_typed 1.0.0 → 1.0.1

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
- SHA1:
3
- metadata.gz: 63551aa968c5f70cc12e5f78968504af5fdd684d
4
- data.tar.gz: a85087575bed96f0853bd590a3ef101e49dd3a9d
2
+ SHA256:
3
+ metadata.gz: 43cd1f89f9649b4c69bc7bf3eb4a9b382b0714e967b0583aab230ae745b554c9
4
+ data.tar.gz: 8e15ff5856fc224f1092bd9599d043e77cd9959272646367200b9f030049ec2a
5
5
  SHA512:
6
- metadata.gz: 6561f15f3e79fdd38f8dcadbdaf26e09fd81881f278e07578ccaeae41c2d0216fa73045879ae5e24a9ee57b23aa6d6de107026ad7f561d2d884213af3c6d1c7f
7
- data.tar.gz: 85c3925fed636794081343ce086294179a72e10702129f1c3e82c09fe4a651c1888d2658d14bd68d65d622a125d557c5a794cc4865a65245bfbcaa4da2e8a77a
6
+ metadata.gz: 49a303ba48a7d09d4088709228e3585d7571a3df8c773a921b50c8750ffb8803383ea5c4a4f536770514043d13bb78eb5e855ba646fbf0ae2a366aa49c265546
7
+ data.tar.gz: c492608d59a98e035ed938170cd033d6018e11d4cfe8ae8fb8345c7d9b31a6bf71ed40e8b69341e52187107fcfe699004019bbe2c76dca5fc1b0eb1ee5bd22dd
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -1,3 +1,3 @@
1
1
  module AttrTyped
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/attr_typed.rb CHANGED
@@ -17,7 +17,7 @@ require "date"
17
17
  #
18
18
  module AttrTyped
19
19
  ALLOWED_TYPES ||= [
20
- :string, :money, :time, :big_decimal, :date, :integer, :boolean, :date_time
20
+ :string, :money, :time, :big_decimal, :date, :integer, :strict_integer, :boolean, :date_time
21
21
  ]
22
22
 
23
23
  def self.included(klass)
@@ -47,6 +47,14 @@ module AttrTyped
47
47
  value.to_i
48
48
  end
49
49
 
50
+ def parse_strict_integer(value)
51
+ return value if value.is_a?(Integer)
52
+ # remove leading zeroes to ensure Integer converts via base 10
53
+ Integer(value.to_s.gsub(/^0+/,''))
54
+ rescue ArgumentError
55
+ nil
56
+ end
57
+
50
58
  def parse_date(value)
51
59
  return value if value.is_a?(Date)
52
60
 
@@ -68,12 +76,16 @@ module AttrTyped
68
76
  return value.to_d if value.is_a?(Float)
69
77
 
70
78
  BigDecimal.new(value)
79
+ rescue ArgumentError
80
+ BigDecimal.new(0)
71
81
  end
72
82
 
73
83
  def parse_money(value)
74
84
  return value if value.is_a?(Money)
75
85
 
76
86
  Monetize.from_bigdecimal(BigDecimal.new(value.to_s))
87
+ rescue ArgumentError
88
+ Money.new(0)
77
89
  end
78
90
 
79
91
  def parse_time(value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_typed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Langhorne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: monetize
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".gitignore"
76
77
  - ".rspec"
77
78
  - Gemfile
78
79
  - LICENSE.txt
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  version: '0'
102
103
  requirements: []
103
104
  rubyforge_project:
104
- rubygems_version: 2.4.5
105
+ rubygems_version: 2.7.3
105
106
  signing_key:
106
107
  specification_version: 4
107
108
  summary: Enforce attribute types at assignment time