business_error 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/business_error.rb +7 -15
- data/lib/business_error/error.rb +1 -1
- data/lib/business_error/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fd914c847e67a508989e809dd25ae32fa9028ec
|
4
|
+
data.tar.gz: c6ca6e67e12fd2f25defb9aca0bd3bc34d1d3a3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aae1f680684090805bab33b9a2d3b98519e6add149bd9c4f8e12ec2364c28257cfe37fd81f29e44fdb75ae529f27314e23ab0261662b375ba541cbad756984d
|
7
|
+
data.tar.gz: 5d62dcfe75cba0eb7560ffb6186e6b26049f2dbcd77f8f7758d2e44007a2aac26969ec6fda63f5b5b0a0511c536c7c20186c5676a844cc39f8a83e1e80b6672f
|
data/Gemfile.lock
CHANGED
data/lib/business_error.rb
CHANGED
@@ -3,10 +3,7 @@ require 'business_error/error'
|
|
3
3
|
require 'business_error/config'
|
4
4
|
|
5
5
|
module BusinessError
|
6
|
-
cattr_accessor
|
7
|
-
{ }
|
8
|
-
end
|
9
|
-
|
6
|
+
cattr_accessor(:defs_tree) { { } }
|
10
7
|
attr_accessor :defs
|
11
8
|
|
12
9
|
def mattr_reader name, message = '', code = _get_code, http: _get_http, group: _get_group
|
@@ -16,21 +13,17 @@ module BusinessError
|
|
16
13
|
# TODO raise Error, name, message, code
|
17
14
|
define_singleton_method("#{name}!") { raise Error.new(name, message, code, http) }
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
((defs_tree[self.name] ||= { })[group] ||= [ ]) << info
|
24
|
-
((@defs ||= { })[group] ||= []) << name
|
25
|
-
end
|
16
|
+
defs_tree[self.name] ||= { }
|
17
|
+
(defs_tree[self.name][group] ||= [ ]) << { name: name, msg: message, code: code, http: http }
|
18
|
+
((@defs ||= { })[group] ||= []) << name
|
26
19
|
end
|
27
20
|
|
28
21
|
alias_method :define, :mattr_reader
|
29
22
|
|
30
|
-
def group group_name = :private, code_start_at =
|
23
|
+
def group group_name = :private, code_start_at = @code, http: _get_http, &block
|
31
24
|
@group_name, @code, @http, group_name, code_start_at, http = group_name, code_start_at, http, @group_name, @code, @http
|
32
25
|
instance_eval(&block)
|
33
|
-
@group_name, @code, @http
|
26
|
+
@group_name, @code, @http = group_name, code_start_at, http
|
34
27
|
end
|
35
28
|
|
36
29
|
def _get_group
|
@@ -38,8 +31,7 @@ module BusinessError
|
|
38
31
|
end
|
39
32
|
|
40
33
|
def _get_code
|
41
|
-
code = @code
|
42
|
-
raise ArgumentError, 'Should give a code to define your business error' if code.nil?
|
34
|
+
raise ArgumentError, 'Should give a code to define your business error' if (code = @code).nil?
|
43
35
|
@code = @code < 0 ? (code - 1) : (code + 1)
|
44
36
|
code
|
45
37
|
end
|
data/lib/business_error/error.rb
CHANGED
@@ -4,7 +4,7 @@ module BusinessError
|
|
4
4
|
class Error < StandardError
|
5
5
|
attr_accessor :name, :msg, :code, :http_status
|
6
6
|
|
7
|
-
def initialize(name, msg, code, http_status =
|
7
|
+
def initialize(name, msg, code, http_status = Config.default_http_status)
|
8
8
|
msg = name.to_s.humanize if msg.blank?
|
9
9
|
@name, @msg, @code, @http_status = name, msg, code, http_status
|
10
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|