lotus-utils 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/lotus/utils/kernel.rb +46 -21
- data/lib/lotus/utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 119e1e01ae231b8dd402f6cda19aa9354663e439
|
4
|
+
data.tar.gz: 5e28d0a9c8e1b06a66acc3ff881ac08908a5b0a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea4c280a6b7c8b693d69bf132b85de349e0c459a4ac259f33d58313244ca97300aae686743f4f15fd00314c41d07b792151f78a02a2e2c75b9d157d4d3f744a3
|
7
|
+
data.tar.gz: 95432308fb5689d4a61292cd24553df16a37e039ac79760debe4813d961dadff081e8ccb993946891e86c57fe77d2e7b85822cd3d2096111031390c1a5d7af6a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Lotus::Utils
|
2
2
|
Ruby core extentions and class utilities for Lotus
|
3
3
|
|
4
|
+
## v0.4.3 - 2015-05-22
|
5
|
+
### Added
|
6
|
+
- [François Beausoleil] Improved `Lotus::Utils::Kernel` messages for `TypeError`.
|
7
|
+
|
4
8
|
## v0.4.2 - 2015-05-15
|
5
9
|
### Fixed
|
6
10
|
- [Luca Guidi] Ensure `Lotus::Utils::Attributes#to_h` to return `::Hash`
|
data/lib/lotus/utils/kernel.rb
CHANGED
@@ -140,7 +140,7 @@ module Lotus
|
|
140
140
|
Set.new(::Kernel.Array(arg))
|
141
141
|
end
|
142
142
|
rescue NoMethodError
|
143
|
-
raise TypeError.new("can't convert into Set")
|
143
|
+
raise TypeError.new("can't convert #{inspect_type_error(arg)}into Set")
|
144
144
|
end
|
145
145
|
|
146
146
|
# Coerces the argument to be a Hash.
|
@@ -205,7 +205,7 @@ module Lotus
|
|
205
205
|
super(arg)
|
206
206
|
end
|
207
207
|
rescue NoMethodError
|
208
|
-
raise TypeError.new "can't convert into Hash"
|
208
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Hash"
|
209
209
|
end
|
210
210
|
else
|
211
211
|
def self.Hash(arg)
|
@@ -217,7 +217,7 @@ module Lotus
|
|
217
217
|
super(arg)
|
218
218
|
end
|
219
219
|
rescue ArgumentError, NoMethodError
|
220
|
-
raise TypeError.new "can't convert into Hash"
|
220
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Hash"
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -336,13 +336,13 @@ module Lotus
|
|
336
336
|
when NilClass, ->(a) { a.respond_to?(:to_i) && a.to_s.match(NUMERIC_MATCHER) }
|
337
337
|
arg.to_i
|
338
338
|
else
|
339
|
-
raise TypeError.new "can't convert into Integer"
|
339
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Integer"
|
340
340
|
end
|
341
341
|
rescue NoMethodError
|
342
|
-
raise TypeError.new "can't convert into Integer"
|
342
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Integer"
|
343
343
|
end
|
344
344
|
rescue RangeError
|
345
|
-
raise TypeError.new "can't convert into Integer"
|
345
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Integer"
|
346
346
|
end
|
347
347
|
|
348
348
|
# Coerces the argument to be a BigDecimal.
|
@@ -426,10 +426,10 @@ module Lotus
|
|
426
426
|
when ->(a) { a.to_s.match(NUMERIC_MATCHER) }
|
427
427
|
BigDecimal.new(arg)
|
428
428
|
else
|
429
|
-
raise TypeError.new "can't convert into BigDecimal"
|
429
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into BigDecimal"
|
430
430
|
end
|
431
431
|
rescue NoMethodError
|
432
|
-
raise TypeError.new "can't convert into BigDecimal"
|
432
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into BigDecimal"
|
433
433
|
end
|
434
434
|
|
435
435
|
# Coerces the argument to be a Float.
|
@@ -552,13 +552,13 @@ module Lotus
|
|
552
552
|
when NilClass, ->(a) { a.respond_to?(:to_f) && a.to_s.match(NUMERIC_MATCHER) }
|
553
553
|
arg.to_f
|
554
554
|
else
|
555
|
-
raise TypeError.new "can't convert into Float"
|
555
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Float"
|
556
556
|
end
|
557
557
|
rescue NoMethodError
|
558
|
-
raise TypeError.new "can't convert into Float"
|
558
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Float"
|
559
559
|
end
|
560
560
|
rescue RangeError
|
561
|
-
raise TypeError.new "can't convert into Float"
|
561
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Float"
|
562
562
|
end
|
563
563
|
|
564
564
|
# Coerces the argument to be a String.
|
@@ -659,14 +659,14 @@ module Lotus
|
|
659
659
|
super(arg)
|
660
660
|
end
|
661
661
|
rescue NoMethodError
|
662
|
-
raise TypeError.new "can't convert into String"
|
662
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into String"
|
663
663
|
end
|
664
664
|
else
|
665
665
|
def self.String(arg)
|
666
666
|
arg = arg.to_str if arg.respond_to?(:to_str)
|
667
667
|
super(arg)
|
668
668
|
rescue NoMethodError
|
669
|
-
raise TypeError.new "can't convert into String"
|
669
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into String"
|
670
670
|
end
|
671
671
|
end
|
672
672
|
|
@@ -731,7 +731,7 @@ module Lotus
|
|
731
731
|
Date.parse(arg.to_s)
|
732
732
|
end
|
733
733
|
rescue ArgumentError, NoMethodError
|
734
|
-
raise TypeError.new "can't convert into Date"
|
734
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Date"
|
735
735
|
end
|
736
736
|
|
737
737
|
# Coerces the argument to be a DateTime.
|
@@ -799,7 +799,7 @@ module Lotus
|
|
799
799
|
DateTime.parse(arg.to_s)
|
800
800
|
end
|
801
801
|
rescue ArgumentError, NoMethodError
|
802
|
-
raise TypeError.new "can't convert into DateTime"
|
802
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into DateTime"
|
803
803
|
end
|
804
804
|
|
805
805
|
# Coerces the argument to be a Time.
|
@@ -864,7 +864,7 @@ module Lotus
|
|
864
864
|
Time.parse(arg.to_s)
|
865
865
|
end
|
866
866
|
rescue ArgumentError, NoMethodError
|
867
|
-
raise TypeError.new "can't convert into Time"
|
867
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Time"
|
868
868
|
end
|
869
869
|
|
870
870
|
# Coerces the argument to be a Boolean.
|
@@ -917,7 +917,7 @@ module Lotus
|
|
917
917
|
!!arg
|
918
918
|
end
|
919
919
|
rescue NoMethodError
|
920
|
-
raise TypeError.new "can't convert into Boolean"
|
920
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Boolean"
|
921
921
|
end
|
922
922
|
|
923
923
|
# Coerces the argument to be a Pathname.
|
@@ -975,7 +975,7 @@ module Lotus
|
|
975
975
|
super
|
976
976
|
end
|
977
977
|
rescue NoMethodError
|
978
|
-
raise TypeError.new "can't convert into Pathname"
|
978
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Pathname"
|
979
979
|
end
|
980
980
|
|
981
981
|
# Coerces the argument to be a String.
|
@@ -1021,13 +1021,38 @@ module Lotus
|
|
1021
1021
|
# Lotus::Utils::Kernel.Symbol(input) # => TypeError
|
1022
1022
|
def self.Symbol(arg)
|
1023
1023
|
case arg
|
1024
|
-
when '' then raise TypeError.new "can't convert into Symbol"
|
1024
|
+
when '' then raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
|
1025
1025
|
when ->(a) { a.respond_to?(:to_sym) } then arg.to_sym
|
1026
1026
|
else
|
1027
|
-
raise TypeError.new "can't convert into Symbol"
|
1027
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
|
1028
1028
|
end
|
1029
1029
|
rescue NoMethodError
|
1030
|
-
raise TypeError.new "can't convert into Symbol"
|
1030
|
+
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
# Returns the most useful type error possible
|
1034
|
+
#
|
1035
|
+
# If the object does not respond_to?(:inspect), we return the class, else we
|
1036
|
+
# return nil. In all cases, this method is tightly bound to callers, as this
|
1037
|
+
# method appends the required space to make the error message look good.
|
1038
|
+
#
|
1039
|
+
# @since 0.4.3
|
1040
|
+
# @api private
|
1041
|
+
def self.inspect_type_error(arg)
|
1042
|
+
(arg.respond_to?(:inspect) ? arg.inspect : arg.to_s) << " "
|
1043
|
+
rescue NoMethodError => _
|
1044
|
+
# missing the #respond_to? method, fall back to returning the class' name
|
1045
|
+
begin
|
1046
|
+
arg.class.name << " instance "
|
1047
|
+
rescue NoMethodError
|
1048
|
+
# missing the #class method, can't fall back to anything better than nothing
|
1049
|
+
# Callers will have to guess from their code
|
1050
|
+
nil
|
1051
|
+
end
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
class << self
|
1055
|
+
private :inspect_type_error
|
1031
1056
|
end
|
1032
1057
|
end
|
1033
1058
|
end
|
data/lib/lotus/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|