koine-attributes 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -0
- data/lib/koine/attributes/adapter/base.rb +13 -1
- data/lib/koine/attributes/adapter/date.rb +6 -4
- data/lib/koine/attributes/adapter/float.rb +1 -1
- data/lib/koine/attributes/adapter/integer.rb +1 -1
- data/lib/koine/attributes/adapter/time.rb +5 -3
- data/lib/koine/attributes/argument_error.rb +19 -0
- data/lib/koine/attributes/attributes_factory.rb +1 -0
- data/lib/koine/attributes/version.rb +1 -1
- data/lib/koine/attributes.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4861f47589ca3917acd1004bfa66db499eda711f
|
4
|
+
data.tar.gz: 1d5f6a2798c9e655b5fcd4659f65cb1d92ff2683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05b50951cb2f648ae979f2c23a7c09f17b442c23ceca28e98fe11e34e1cd25906b4e920ce056b3c9144cad36b719b33fe66d87ab56a19fdaa4c4431efd85e44f
|
7
|
+
data.tar.gz: db69bb585e013ed1f1ea95e05c6b550011864e79f2e3b687535bab52a3e6f45fc0dbee50c81a8a5ca684bebeb3cead9dcce929b1e4c43f2a88aa5f31c5e03117
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@ module Koine
|
|
2
2
|
module Attributes
|
3
3
|
module Adapter
|
4
4
|
class Base
|
5
|
+
attr_accessor :attribute_name
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@attribute_name = 'AnonymousAttribute'
|
9
|
+
end
|
10
|
+
|
5
11
|
def coerce(value)
|
6
12
|
return coerce_nil if value.nil?
|
7
13
|
|
@@ -34,7 +40,7 @@ module Koine
|
|
34
40
|
return @nil_value.respond_to?(:call) ? @nil_value.call : @nil_value
|
35
41
|
end
|
36
42
|
|
37
|
-
raise ArgumentError, 'Cannot be nil'
|
43
|
+
raise ArgumentError, 'Cannot be nil', attribute_name
|
38
44
|
end
|
39
45
|
|
40
46
|
def coerce_not_nil(_value)
|
@@ -51,6 +57,12 @@ module Koine
|
|
51
57
|
|
52
58
|
value.freeze
|
53
59
|
end
|
60
|
+
|
61
|
+
def wrap_errors
|
62
|
+
yield
|
63
|
+
rescue StandardError => error
|
64
|
+
raise Koine::Attributes::ArgumentError.new(error, attribute_name)
|
65
|
+
end
|
54
66
|
end
|
55
67
|
end
|
56
68
|
end
|
@@ -5,10 +5,12 @@ module Koine
|
|
5
5
|
private
|
6
6
|
|
7
7
|
def coerce_not_nil(date)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
wrap_errors do
|
9
|
+
secure do
|
10
|
+
next date if date.is_a?(::Date)
|
11
|
+
next date.to_date if date.is_a?(::Time)
|
12
|
+
::Date.parse(date)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Koine
|
2
|
+
module Attributes
|
3
|
+
class ArgumentError < ::ArgumentError
|
4
|
+
attr_reader :attribute_name
|
5
|
+
|
6
|
+
def initialize(error, attribute_name = nil)
|
7
|
+
@attribute_name = attribute_name
|
8
|
+
|
9
|
+
if error.is_a?(Exception)
|
10
|
+
super(error.message)
|
11
|
+
set_backtrace(error.backtrace)
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
super(error)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/koine/attributes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'koine/attributes/version'
|
2
2
|
require 'koine/attributes/adapter/base'
|
3
|
+
require 'koine/attributes/argument_error'
|
3
4
|
|
4
5
|
# provides the following API
|
5
6
|
#
|
@@ -139,7 +140,7 @@ module Koine
|
|
139
140
|
define_method(:initialize) { |*args| attributes.initialize_values(*args) }
|
140
141
|
|
141
142
|
define_method(:inspect) do
|
142
|
-
hex_id = '%x'
|
143
|
+
hex_id = format('%x', (object_id << 1))
|
143
144
|
"#<#{self.class}:0x00#{hex_id} @attributes=#{attributes.to_h.inspect}>"
|
144
145
|
end
|
145
146
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
@@ -138,6 +138,7 @@ 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
|
141
142
|
- lib/koine/attributes/attributes.rb
|
142
143
|
- lib/koine/attributes/attributes_factory.rb
|
143
144
|
- lib/koine/attributes/hash_helper.rb
|
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.6.14.1
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: Stronger setters and getters
|