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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24f7f625ccbf74d8eda291d6cd1899ef00b5716b9e8da568318b3e4d7022e224
4
- data.tar.gz: 052353c86512d14717a3a79c96e82da73154cd36a2ac41cf4b59b347ec0de097
3
+ metadata.gz: 47fbe7b08376e927e948208ade0525696d55f381ccb1879bd1ce1ec501d19fdf
4
+ data.tar.gz: 26655df66f3199ed26886426861c276fd8aa2d6afc51ccc0ae26ec7831707550
5
5
  SHA512:
6
- metadata.gz: 381c3e3e97108c8adaf5100ef291ceab6e7aaaf7cd405c9184888ce8bc0bf7c63670b304722c9d2c86907f83ac48caf985fe7f4f1c8043168bfff01fb5008caa
7
- data.tar.gz: 8a47804574a9ea67a918faecbcf5ec95362b6017871790470062030b69390f1e3dcbea3d5eb611a984eada76ad52dbc5d1645e649d170fd95577fc335a9bc595
6
+ metadata.gz: 512e9c04a9d05199bc91deb74408065536d70b3ab4c6b86b8632b3a072e9060f7696a057f176c1721dfe8e2605bd581016fb57cffae3c0c0eb3d399054e93f1b
7
+ data.tar.gz: ee30b2ee6b9373b53845441b9cd567dbb5accfd0a7583007f43237bd4ede65494dd5e4adb853ec86e7728637ff9a726f188e7877bfb458887db4fde1f0935e85
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.2'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
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
- @errorio_collection_types = collection_types.map(&:to_sym)
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
- err_obj = err.options.merge(key: err.attribute, type: err.type, message: err.message)
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.2
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-08-09 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler