koine-attributes 1.1.0 → 1.2.0
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/README.md +0 -1
- data/lib/koine/attributes.rb +2 -1
- data/lib/koine/attributes/adapter/base.rb +7 -3
- data/lib/koine/attributes/adapter/boolean.rb +1 -1
- data/lib/koine/attributes/attributes.rb +2 -2
- data/lib/koine/attributes/{argument_error.rb → invalid_attribute_error.rb} +5 -4
- data/lib/koine/attributes/invalid_attributes_error.rb +6 -0
- data/lib/koine/attributes/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 177452f3f12545dbcaf9a2b57043de1f2efb0d93
|
4
|
+
data.tar.gz: 52749eb82a9d367a7b2a2a12298fa1cc6c072770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d847fb964cbed0f0c6889c8737e133a4cc9c369dafc4d4b2403634998afff288c8ea648855ab79f53f388139248a45344c7b9d3d35d3d5697a9466caa6dabd
|
7
|
+
data.tar.gz: 1d88d2820b0b64408e4c53fd1da2310afd84c32b692c8a2ad0f95ec5d2aa63426c78e40119fd90d241e1452736dbb1f1538e1305126cf65328fb6d474724ced2
|
data/README.md
CHANGED
@@ -11,7 +11,6 @@ Yes, there are [so many alternative solutions already](#alternative-solutions)!
|
|
11
11
|
[](https://codeclimate.com/github/mjacobus/koine-attributes)
|
12
12
|
|
13
13
|
[](https://badge.fury.io/rb/koine-attributes)
|
14
|
-
[](https://gemnasium.com/github.com/mjacobus/koine-attributes)
|
15
14
|
|
16
15
|
## Installation
|
17
16
|
|
data/lib/koine/attributes.rb
CHANGED
@@ -5,7 +5,7 @@ module Koine
|
|
5
5
|
attr_accessor :attribute_name
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@attribute_name = '
|
8
|
+
@attribute_name = 'annonymous_attribute_name'
|
9
9
|
end
|
10
10
|
|
11
11
|
def coerce(value)
|
@@ -40,7 +40,7 @@ module Koine
|
|
40
40
|
return @nil_value.respond_to?(:call) ? @nil_value.call : @nil_value
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
raise_error('Cannot be nil')
|
44
44
|
end
|
45
45
|
|
46
46
|
def coerce_not_nil(_value)
|
@@ -61,7 +61,11 @@ module Koine
|
|
61
61
|
def wrap_errors
|
62
62
|
yield
|
63
63
|
rescue StandardError => error
|
64
|
-
|
64
|
+
raise_error(error)
|
65
|
+
end
|
66
|
+
|
67
|
+
def raise_error(message)
|
68
|
+
raise Koine::Attributes::InvalidAttributeError.new(message, attribute_name)
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|
@@ -31,7 +31,7 @@ module Koine
|
|
31
31
|
def coerce_not_nil(value)
|
32
32
|
return true if true_values.include?(value)
|
33
33
|
return false if false_values.include?(value)
|
34
|
-
raise
|
34
|
+
raise InvalidAttributeError.new("Invalid argument '#{value}'", attribute_name)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -14,7 +14,7 @@ module Koine
|
|
14
14
|
|
15
15
|
def initialize_values(values = {})
|
16
16
|
if !@initializer[:initialize] && !values.empty?
|
17
|
-
raise
|
17
|
+
raise InvalidAttributesError, "wrong number of arguments (given #{values.length}, expected 0)"
|
18
18
|
end
|
19
19
|
|
20
20
|
return unless @initializer[:initialize]
|
@@ -30,7 +30,7 @@ module Koine
|
|
30
30
|
end
|
31
31
|
|
32
32
|
unless invalid_attributes.empty?
|
33
|
-
raise
|
33
|
+
raise InvalidAttributesError, "Invalid attributes (#{invalid_attributes.join(', ')})"
|
34
34
|
end
|
35
35
|
|
36
36
|
values.each do |attribute, value|
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module Koine
|
2
2
|
module Attributes
|
3
|
-
class
|
3
|
+
class InvalidAttributeError < ::ArgumentError
|
4
4
|
attr_reader :attribute_name
|
5
5
|
|
6
|
-
def initialize(error, attribute_name
|
6
|
+
def initialize(error, attribute_name)
|
7
7
|
@attribute_name = attribute_name
|
8
8
|
|
9
9
|
if error.is_a?(Exception)
|
10
|
-
super(error.message)
|
11
10
|
set_backtrace(error.backtrace)
|
12
|
-
|
11
|
+
error = error.message
|
13
12
|
end
|
14
13
|
|
14
|
+
error = "#{attribute_name}: #{error}" if attribute_name
|
15
|
+
|
15
16
|
super(error)
|
16
17
|
end
|
17
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koine-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
@@ -138,10 +138,11 @@ files:
|
|
138
138
|
- lib/koine/attributes/adapter/string.rb
|
139
139
|
- lib/koine/attributes/adapter/symbol.rb
|
140
140
|
- lib/koine/attributes/adapter/time.rb
|
141
|
-
- lib/koine/attributes/argument_error.rb
|
142
141
|
- lib/koine/attributes/attributes.rb
|
143
142
|
- lib/koine/attributes/attributes_factory.rb
|
144
143
|
- lib/koine/attributes/hash_helper.rb
|
144
|
+
- lib/koine/attributes/invalid_attribute_error.rb
|
145
|
+
- lib/koine/attributes/invalid_attributes_error.rb
|
145
146
|
- lib/koine/attributes/version.rb
|
146
147
|
homepage: https://github.com/mjacobus/koine-attributes
|
147
148
|
licenses:
|