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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 502cae76ac9417bc9e015ce437234a58a26474e97529d93382ec71f392d04239
4
- data.tar.gz: 220e4104a31586d23be4ac26a778c0f528eea61642fddce1068319c314d9757c
3
+ metadata.gz: 5ed495d28642324935bb880c1018fc920dee3baf6efc2e1fa6ce27060195d8ab
4
+ data.tar.gz: 77cbf46514c72e3b580c42eb473b8422edca11b852ba09ff6695bd438c29dfd2
5
5
  SHA512:
6
- metadata.gz: a3d9bd34ac75ed7a812ae791e50b6c335f12a7afc58797fcd620bd24b54fc37dce0bb8d9aa8c29bad483d0f7948a6ec4f6f7a03f6baff7a760f670b2db94ae8f
7
- data.tar.gz: 562ca8487183bffab92272d0e816b9e13228af3bc9a2a30c6d5c2ba278854703f7c79d8fe2eea31ba0694dfb89bdcb745f76dbe0e23a92f0b55e962d12a0de7c
6
+ metadata.gz: 4aab1707ea9d94a2e222d521f6432394c4115eb39189660db22f0b72d9a119301b7b458b3a873f5b9003a57149a68bf38531517021c46ea80d6dd1db60890147
7
+ data.tar.gz: ebabb5a96fd76f4f4d4a18cebd5f62e385f0673391110a38007a06aa52b89a2da80b02318461c7aae7063fd1350f3c8adc5bf600e645faba4e4bff4d29c08c6f
data/.gitignore CHANGED
@@ -6,4 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- /.idea
9
+ /.idea
10
+
11
+ /notes.txt
@@ -10,7 +10,7 @@ module Errorio
10
10
  # invited_by: 1823
11
11
  # }
12
12
  def self.by_code(code, args = {})
13
- msg = I18n.t("errorio.messages.#{code}", args)
13
+ msg = I18n.t("errorio.messages.#{code}", **args)
14
14
  {
15
15
  code: code,
16
16
  message: msg
@@ -12,14 +12,33 @@ module Errorio
12
12
  @errors = []
13
13
  end
14
14
 
15
- def add(attribute, type = :invalid, **options)
16
- error = Error.new(@base, attribute, type, **options)
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"]}
@@ -1,3 +1,3 @@
1
1
  module Errorio
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
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.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-07-07 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler