attr_typed 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +3 -1
- data/attr_typed.gemspec +8 -5
- data/lib/attr_typed.rb +11 -10
- data/lib/attr_typed/version.rb +3 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c7f130030e5e764a67034274f152a01f614bff460d5838e3c5931b28b164abb
|
4
|
+
data.tar.gz: d94dd0eb7dcb00158254c05c2360ccf292d9de6fdae4a5859e63ac207c94b478
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f3491dc81c066a365aebf0af6b444a0bf6698507179fe6912d4b23f87d8e0bfa1b984e1feea3c42978727920622ce65ef5ef83d7d46033e13b40117b59fca17
|
7
|
+
data.tar.gz: a4cfefa65918e3c628250c7574c88165f2af8f02994fab35c3c311720b4a8cc582b48ec036e6fb6d28f9e192117a7ba8a22ec21504a5ad380716447ecda91b46
|
data/Rakefile
CHANGED
data/attr_typed.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'attr_typed/version'
|
5
6
|
|
@@ -9,16 +10,18 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ["Anthony Langhorne", "Tom Meier"]
|
10
11
|
spec.email = ["anthony.langhorne@ferocia.com.au", "thomas.meier@ferocia.com.au"]
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
+
spec.summary = "Enforce attribute types at assignment time"
|
13
14
|
spec.homepage = "https://github.com/Ferocia/attr_typed"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
17
|
+
spec.required_ruby_version = '>= 2.4.0'
|
18
|
+
|
16
19
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
20
|
spec.require_paths = ["lib"]
|
18
21
|
|
19
22
|
spec.add_dependency 'monetize', '>= 1.0.0'
|
20
23
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.
|
22
|
-
spec.add_development_dependency "rake", "~>
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.1.4"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
23
26
|
spec.add_development_dependency "rspec"
|
24
27
|
end
|
data/lib/attr_typed.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "monetize"
|
2
4
|
require "money"
|
3
5
|
require "bigdecimal"
|
@@ -16,9 +18,9 @@ require "date"
|
|
16
18
|
# - Due to the way string.to_f works in ruby, self.my_field = "cats" will equal $0.00
|
17
19
|
#
|
18
20
|
module AttrTyped
|
19
|
-
ALLOWED_TYPES ||= [
|
20
|
-
|
21
|
-
]
|
21
|
+
ALLOWED_TYPES ||= %i[
|
22
|
+
string money time big_decimal date integer strict_integer boolean date_time
|
23
|
+
].freeze
|
22
24
|
|
23
25
|
def self.included(klass)
|
24
26
|
klass.extend(ClassMethods)
|
@@ -31,9 +33,7 @@ module AttrTyped
|
|
31
33
|
def parse_typed_value(value, type)
|
32
34
|
public_send("parse_#{type}", value) unless value.nil?
|
33
35
|
rescue ArgumentError => e
|
34
|
-
|
35
|
-
AttrTyped.logger.error("Error parsing '#{value}' into a #{type}")
|
36
|
-
end
|
36
|
+
AttrTyped&.logger&.error("Error parsing '#{value}' into a #{type}")
|
37
37
|
raise e
|
38
38
|
end
|
39
39
|
|
@@ -50,6 +50,7 @@ module AttrTyped
|
|
50
50
|
def parse_strict_integer(value)
|
51
51
|
return value if value.nil? || value.is_a?(Integer)
|
52
52
|
return value.to_i if value.is_a?(Float) || value.is_a?(BigDecimal)
|
53
|
+
|
53
54
|
Integer(value, 10)
|
54
55
|
rescue ArgumentError
|
55
56
|
nil
|
@@ -75,15 +76,15 @@ module AttrTyped
|
|
75
76
|
return value if value.is_a?(BigDecimal)
|
76
77
|
return value.to_d if value.is_a?(Float)
|
77
78
|
|
78
|
-
BigDecimal
|
79
|
+
BigDecimal(value)
|
79
80
|
rescue ArgumentError
|
80
|
-
BigDecimal
|
81
|
+
BigDecimal(0)
|
81
82
|
end
|
82
83
|
|
83
84
|
def parse_money(value)
|
84
85
|
return value if value.is_a?(Money)
|
85
86
|
|
86
|
-
Monetize.from_bigdecimal(BigDecimal
|
87
|
+
Monetize.from_bigdecimal(BigDecimal(value.to_s))
|
87
88
|
rescue ArgumentError
|
88
89
|
Money.new(0)
|
89
90
|
end
|
@@ -100,7 +101,7 @@ module AttrTyped
|
|
100
101
|
return if value.nil? && !value.is_a?(FalseClass)
|
101
102
|
return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
102
103
|
|
103
|
-
[
|
104
|
+
%w[true y].include?(value.to_s.downcase)
|
104
105
|
end
|
105
106
|
|
106
107
|
# Class method attr_typed
|
data/lib/attr_typed/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_typed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Langhorne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: monetize
|
@@ -31,28 +31,28 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 2.1.4
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 2.1.4
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '12.0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '12.0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,15 +96,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
requirements:
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
99
|
+
version: 2.4.0
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.6.11
|
106
|
+
rubygems_version: 3.1.4
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: Enforce attribute types at assignment time
|