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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03f3d6fe7cf150f25957f59b9561a81998fa8e32
4
- data.tar.gz: 2fe04dd5482c192c8df84126cfd8f9fde503ac04
3
+ metadata.gz: 5fd914c847e67a508989e809dd25ae32fa9028ec
4
+ data.tar.gz: c6ca6e67e12fd2f25defb9aca0bd3bc34d1d3a3e
5
5
  SHA512:
6
- metadata.gz: dadeb522683dbcf0a4e45aa1244fc23dbc35f293978c539b7a54197a8e625701c8ab36cbf5f1fa9ff5f86575df6f93480488db290f6516078e3e3b2b41a76a86
7
- data.tar.gz: db9707231f798b4c07acacc36e4296385ef4996e1e71081ed158b7b0ccb56ee612b16a9cec46f47365a75c87f559b1631be54c43de1bac9aa632f92723f4f15f
6
+ metadata.gz: 0aae1f680684090805bab33b9a2d3b98519e6add149bd9c4f8e12ec2364c28257cfe37fd81f29e44fdb75ae529f27314e23ab0261662b375ba541cbad756984d
7
+ data.tar.gz: 5d62dcfe75cba0eb7560ffb6186e6b26049f2dbcd77f8f7758d2e44007a2aac26969ec6fda63f5b5b0a0511c536c7c20186c5676a844cc39f8a83e1e80b6672f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- business_error (1.0.1)
4
+ business_error (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,4 +32,4 @@ DEPENDENCIES
32
32
  rspec (~> 3.0)
33
33
 
34
34
  BUNDLED WITH
35
- 1.16.4
35
+ 1.16.6
@@ -3,10 +3,7 @@ require 'business_error/error'
3
3
  require 'business_error/config'
4
4
 
5
5
  module BusinessError
6
- cattr_accessor :defs_tree do
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
- info = { name: name, msg: message, code: code, http: http }
20
- if group == :public
21
- (defs_tree[:public] ||= [ ]) << info
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 = nil, http: 200, &block
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, group_name, code_start_at, http = group_name, code_start_at, http, @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
@@ -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 = 200)
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
@@ -1,3 +1,3 @@
1
1
  module BusinessError
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  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.1
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-14 00:00:00.000000000 Z
11
+ date: 2018-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler