errorio 0.1.2 → 0.1.6
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 +1 -1
- data/lib/errorio/errors.rb +21 -2
- data/lib/errorio/version.rb +1 -1
- data/lib/errorio.rb +12 -5
- 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: 47fbe7b08376e927e948208ade0525696d55f381ccb1879bd1ce1ec501d19fdf
|
4
|
+
data.tar.gz: 26655df66f3199ed26886426861c276fd8aa2d6afc51ccc0ae26ec7831707550
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512e9c04a9d05199bc91deb74408065536d70b3ab4c6b86b8632b3a072e9060f7696a057f176c1721dfe8e2605bd581016fb57cffae3c0c0eb3d399054e93f1b
|
7
|
+
data.tar.gz: ee30b2ee6b9373b53845441b9cd567dbb5accfd0a7583007f43237bd4ede65494dd5e4adb853ec86e7728637ff9a726f188e7877bfb458887db4fde1f0935e85
|
data/.gitignore
CHANGED
data/lib/errorio/details.rb
CHANGED
data/lib/errorio/errors.rb
CHANGED
@@ -12,14 +12,33 @@ module Errorio
|
|
12
12
|
@errors = []
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
# Adds a new error to errors collection
|
16
|
+
#
|
17
|
+
# @param [Symbol] attribute
|
18
|
+
# @param [Symbol] type
|
19
|
+
# @param [Hash] options
|
20
|
+
def add(attribute, type = :invalid, options = {})
|
21
|
+
error = Error.new(@base, attribute, type, options)
|
17
22
|
|
18
23
|
@errors.append(error)
|
19
24
|
|
20
25
|
error
|
21
26
|
end
|
22
27
|
|
28
|
+
# Copy errors from another errors object
|
29
|
+
#
|
30
|
+
# @param [Errorio::Errors,ActiveModel::Errors] other
|
31
|
+
def copy(other)
|
32
|
+
other.each do |err|
|
33
|
+
options = err.options
|
34
|
+
|
35
|
+
# ActiveModel::Error object has own way to generate message attribute,
|
36
|
+
options[:message] = err.message if err.is_a?(ActiveModel::Error)
|
37
|
+
|
38
|
+
add err.attribute, err.type, options
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
23
42
|
# Returns all error attribute names
|
24
43
|
#
|
25
44
|
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
|
data/lib/errorio/version.rb
CHANGED
data/lib/errorio.rb
CHANGED
@@ -123,12 +123,18 @@ module Errorio
|
|
123
123
|
# Class-level methods
|
124
124
|
module ClassMethods
|
125
125
|
def errorionize(*collection_types)
|
126
|
-
raise unless collection_types.is_a?(Array)
|
127
|
-
|
126
|
+
raise 'InapproriateArguments' unless collection_types.is_a?(Array)
|
127
|
+
|
128
|
+
@errorio_collection_types ||= []
|
129
|
+
collection_types.map(&:to_sym).each do |a|
|
130
|
+
next if @errorio_collection_types.include?(a)
|
131
|
+
|
132
|
+
@errorio_collection_types << a
|
133
|
+
end
|
128
134
|
end
|
129
135
|
|
130
136
|
def errorio_collection_types
|
131
|
-
@errorio_collection_types
|
137
|
+
@errorio_collection_types || [:errors]
|
132
138
|
end
|
133
139
|
end
|
134
140
|
|
@@ -140,7 +146,7 @@ module Errorio
|
|
140
146
|
end
|
141
147
|
|
142
148
|
def errorio_initializer
|
143
|
-
@errorio_repo
|
149
|
+
@errorio_repo ||= {}
|
144
150
|
self.class.errorio_collection_types.each do |e|
|
145
151
|
init_errors_variable(e)
|
146
152
|
if send(e).nil?
|
@@ -179,7 +185,8 @@ module Errorio
|
|
179
185
|
result = []
|
180
186
|
|
181
187
|
@errors.each do |err|
|
182
|
-
|
188
|
+
msg = err.options.key?(:message) ? err.options[:message] : err.message
|
189
|
+
err_obj = err.options.merge(key: err.attribute, type: err.type, message: msg)
|
183
190
|
result << err_obj
|
184
191
|
end
|
185
192
|
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.6
|
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-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|