errorio 0.1.4 → 0.1.8
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/.gitignore +3 -1
- data/lib/errorio/details.rb +17 -1
- data/lib/errorio/errors.rb +6 -3
- data/lib/errorio/version.rb +1 -1
- data/lib/errorio.rb +23 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4600030389e73944613c2aaaddf63e373c7b630406843fce1faed4b75e072be1
|
4
|
+
data.tar.gz: 2bba836bff4250850fd87d203a32b57bd7db08c6796884647de050aa6499fe67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a441bf819e19ed12c7e3a64b1b024b778e7a7695a7dcb77d41e5d5544cc6181b3e2deacf34f63398e9e294e92a544d9e7c9cd9fcea1e970510eec184af894cd8
|
7
|
+
data.tar.gz: e6ad7899eac16b820d7b414bc3c58b1e4c04b68751002349b6723944e9299df4fdaeeab168ba7ddcf0ed2cf539205f841efa99c5608234fe490905657ab75346
|
data/.gitignore
CHANGED
data/lib/errorio/details.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
module Errorio
|
2
2
|
# Some helpers
|
3
3
|
class Details
|
4
|
+
# Interpolate error message from i18n
|
5
|
+
#
|
6
|
+
# @param [Symbol] code
|
7
|
+
# @param [Hash] args
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
def self.t_msg(code, args = {})
|
12
|
+
I18n.t("errorio.messages.#{code}", **args)
|
13
|
+
end
|
14
|
+
|
4
15
|
# Error details by code:
|
5
16
|
#
|
6
17
|
# errors.add :base, :invalid, Errorio.by_code(:E0001, user_id: 129)
|
@@ -9,8 +20,13 @@ module Errorio
|
|
9
20
|
# message: "Invitation from user with ID 1823 was expired"
|
10
21
|
# invited_by: 1823
|
11
22
|
# }
|
23
|
+
#
|
24
|
+
# @param [Symbol] code
|
25
|
+
# @param [Hash] args
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
12
28
|
def self.by_code(code, args = {})
|
13
|
-
msg =
|
29
|
+
msg = t_msg(code, args)
|
14
30
|
{
|
15
31
|
code: code,
|
16
32
|
message: msg
|
data/lib/errorio/errors.rb
CHANGED
@@ -26,15 +26,18 @@ module Errorio
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Copy errors from another errors object
|
29
|
-
#
|
30
|
-
# @param [Errorio::Errors,ActiveModel::Errors] other
|
29
|
+
#
|
30
|
+
# @param [Errorio::Errors, ActiveModel::Errors] other
|
31
31
|
def copy(other)
|
32
32
|
other.each do |err|
|
33
33
|
options = err.options
|
34
34
|
|
35
35
|
# ActiveModel::Error object has own way to generate message attribute,
|
36
|
-
|
36
|
+
# try to copy message as the property of `options`
|
37
37
|
|
38
|
+
if err.is_a?(ActiveModel::Error) || err.is_a?(ActiveModel::NestedError) && options[:message].blank?
|
39
|
+
options[:message] = err.message
|
40
|
+
end
|
38
41
|
add err.attribute, err.type, options
|
39
42
|
end
|
40
43
|
end
|
data/lib/errorio/version.rb
CHANGED
data/lib/errorio.rb
CHANGED
@@ -105,9 +105,21 @@ module Errorio
|
|
105
105
|
# Error details with code
|
106
106
|
#
|
107
107
|
# errors.add :base, :invalid, Errorio.by_code(:E0001, user_id: 129)
|
108
|
+
#
|
108
109
|
def by_code(*args)
|
109
110
|
Details.by_code(*args)
|
110
111
|
end
|
112
|
+
|
113
|
+
# Interpolate error message from i18n
|
114
|
+
#
|
115
|
+
# @param [Symbol] code
|
116
|
+
# @param [Hash{Symbol->Object}] args
|
117
|
+
#
|
118
|
+
# @return [String]
|
119
|
+
#
|
120
|
+
def message(code, args = {})
|
121
|
+
Details.t_msg(code, args)
|
122
|
+
end
|
111
123
|
end
|
112
124
|
|
113
125
|
def self.included(base)
|
@@ -123,8 +135,14 @@ module Errorio
|
|
123
135
|
# Class-level methods
|
124
136
|
module ClassMethods
|
125
137
|
def errorionize(*collection_types)
|
126
|
-
raise unless collection_types.is_a?(Array)
|
127
|
-
|
138
|
+
raise 'InapproriateArguments' unless collection_types.is_a?(Array)
|
139
|
+
|
140
|
+
@errorio_collection_types ||= []
|
141
|
+
collection_types.map(&:to_sym).each do |a|
|
142
|
+
next if @errorio_collection_types.include?(a)
|
143
|
+
|
144
|
+
@errorio_collection_types << a
|
145
|
+
end
|
128
146
|
end
|
129
147
|
|
130
148
|
def errorio_collection_types
|
@@ -140,7 +158,7 @@ module Errorio
|
|
140
158
|
end
|
141
159
|
|
142
160
|
def errorio_initializer
|
143
|
-
@errorio_repo
|
161
|
+
@errorio_repo ||= {}
|
144
162
|
self.class.errorio_collection_types.each do |e|
|
145
163
|
init_errors_variable(e)
|
146
164
|
if send(e).nil?
|
@@ -179,7 +197,8 @@ module Errorio
|
|
179
197
|
result = []
|
180
198
|
|
181
199
|
@errors.each do |err|
|
182
|
-
|
200
|
+
msg = err.options.key?(:message) ? err.options[:message] : err.message
|
201
|
+
err_obj = err.options.merge(key: err.attribute, type: err.type, message: msg)
|
183
202
|
result << err_obj
|
184
203
|
end
|
185
204
|
result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errorio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadym Lukavyi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|