errorio 0.1.1 → 0.1.5
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 +6 -1
- 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: 5ed495d28642324935bb880c1018fc920dee3baf6efc2e1fa6ce27060195d8ab
|
4
|
+
data.tar.gz: 77cbf46514c72e3b580c42eb473b8422edca11b852ba09ff6695bd438c29dfd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aab1707ea9d94a2e222d521f6432394c4115eb39189660db22f0b72d9a119301b7b458b3a873f5b9003a57149a68bf38531517021c46ea80d6dd1db60890147
|
7
|
+
data.tar.gz: ebabb5a96fd76f4f4d4a18cebd5f62e385f0673391110a38007a06aa52b89a2da80b02318461c7aae7063fd1350f3c8adc5bf600e645faba4e4bff4d29c08c6f
|
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
@@ -113,6 +113,11 @@ module Errorio
|
|
113
113
|
def self.included(base)
|
114
114
|
base.extend ClassMethods
|
115
115
|
base.send :prepend, InstanceMethods
|
116
|
+
|
117
|
+
# Patch for ActiveRecord classes
|
118
|
+
# AR doesn't call `initialize` method for objects that created on data that was fetched from database,
|
119
|
+
# so you cannot override it. You must use `after_initialize` callback to do that.
|
120
|
+
base.after_initialize :errorio_initializer if base.respond_to?(:after_initialize)
|
116
121
|
end
|
117
122
|
|
118
123
|
# Class-level methods
|
@@ -123,7 +128,7 @@ module Errorio
|
|
123
128
|
end
|
124
129
|
|
125
130
|
def errorio_collection_types
|
126
|
-
@errorio_collection_types
|
131
|
+
@errorio_collection_types || [:errors]
|
127
132
|
end
|
128
133
|
end
|
129
134
|
|
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.5
|
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-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|