net_status 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +0 -1
- data/Gemfile.lock +82 -0
- data/lib/net_status.rb +11 -1
- data/lib/net_status/exception.rb +32 -13
- data/lib/net_status/hash.rb +26 -0
- data/lib/net_status/version.rb +1 -1
- data/net_status.gemspec +3 -0
- metadata +38 -3
- data/lib/net_status/mixin.rb +0 -16
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmRiNmEzN2Q3NTlhZjZjYjhhMzgzYjE2NmNlODk4NzJmNDEwMzAyYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWU4ZDhlZjZkZWQzOTI4YmQ4NDBhNmRiYjNkZWFmZDQwMTZhMzJlZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTA3ZTcxZDZlMjY2YTZiYWM1OGQ3NTE1YTIwMTQzZmQ4OTNhOTk0Y2UyNTBh
|
10
|
+
OGMwOGQ0ZjliMDBhOWI1NjJkOTYxMTI2NzgwOWFiYjE4N2Q3ZDZhOWU4OGE3
|
11
|
+
MDk4MjYyNmU0NTkzM2YyMjZiMmRmOGNmYTljYjIzNmE0OWRiMWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzY4YjI5Mzg4YzU1Y2UyMjdjZjNjMGUzOTI1MGY5NThlYTMxNzdjNDM2Yjhk
|
14
|
+
ZTNiMWY2MTRiMjI0OTRkZTAyNzY5Njg2NDRlZmZmM2JmZTQ3YzNmNGE4OGJk
|
15
|
+
ODVlMTczOWVjZDk2OTE3YzVhMjlmOTkzNDk2ZjRmZDQwMjA5N2I=
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
net_status (0.1.0)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.4.0)
|
11
|
+
backports (3.6.8)
|
12
|
+
coderay (1.1.1)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
ethon (0.9.0)
|
15
|
+
ffi (>= 1.3.0)
|
16
|
+
faraday (0.9.2)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
faraday_middleware (0.10.0)
|
19
|
+
faraday (>= 0.7.4, < 0.10)
|
20
|
+
ffi (1.9.10)
|
21
|
+
gh (0.14.0)
|
22
|
+
addressable
|
23
|
+
backports
|
24
|
+
faraday (~> 0.8)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
net-http-persistent (>= 2.7)
|
27
|
+
net-http-pipeline
|
28
|
+
highline (1.7.8)
|
29
|
+
i18n (0.7.0)
|
30
|
+
json (1.8.3)
|
31
|
+
launchy (2.4.3)
|
32
|
+
addressable (~> 2.3)
|
33
|
+
method_source (0.8.2)
|
34
|
+
multi_json (1.11.3)
|
35
|
+
multipart-post (2.0.0)
|
36
|
+
net-http-persistent (2.9.4)
|
37
|
+
net-http-pipeline (1.0.1)
|
38
|
+
pry (0.10.3)
|
39
|
+
coderay (~> 1.1.0)
|
40
|
+
method_source (~> 0.8.1)
|
41
|
+
slop (~> 3.4)
|
42
|
+
pusher-client (0.6.2)
|
43
|
+
json
|
44
|
+
websocket (~> 1.0)
|
45
|
+
rake (10.5.0)
|
46
|
+
rspec (3.4.0)
|
47
|
+
rspec-core (~> 3.4.0)
|
48
|
+
rspec-expectations (~> 3.4.0)
|
49
|
+
rspec-mocks (~> 3.4.0)
|
50
|
+
rspec-core (3.4.4)
|
51
|
+
rspec-support (~> 3.4.0)
|
52
|
+
rspec-expectations (3.4.0)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.4.0)
|
55
|
+
rspec-mocks (3.4.1)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.4.0)
|
58
|
+
rspec-support (3.4.1)
|
59
|
+
slop (3.6.0)
|
60
|
+
travis (1.8.2)
|
61
|
+
backports
|
62
|
+
faraday (~> 0.9)
|
63
|
+
faraday_middleware (~> 0.9, >= 0.9.1)
|
64
|
+
gh (~> 0.13)
|
65
|
+
highline (~> 1.6)
|
66
|
+
launchy (~> 2.1)
|
67
|
+
pusher-client (~> 0.4)
|
68
|
+
typhoeus (~> 0.6, >= 0.6.8)
|
69
|
+
typhoeus (0.8.0)
|
70
|
+
ethon (>= 0.8.0)
|
71
|
+
websocket (1.2.3)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
ruby
|
75
|
+
|
76
|
+
DEPENDENCIES
|
77
|
+
bundler (~> 1.7)
|
78
|
+
net_status!
|
79
|
+
pry (>= 0.10.3, < 1.0)
|
80
|
+
rake (~> 10.0)
|
81
|
+
rspec (~> 3.4, >= 3.4.0)
|
82
|
+
travis (~> 1.8, >= 1.8.2)
|
data/lib/net_status.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
require "net_status/version"
|
2
2
|
|
3
3
|
require "net_status/exception"
|
4
|
-
require "net_status/
|
4
|
+
require "net_status/hash"
|
5
|
+
|
6
|
+
module NetStatus
|
7
|
+
def self.normalize(net_status, context: nil)
|
8
|
+
code = net_status[:code]
|
9
|
+
code ||= net_status[:error] if net_status.include? :error
|
10
|
+
net_status[:data] ||= {}
|
11
|
+
net_status[:message] = I18n.t [:net_status, context, code].join('.'), [:net_status, code].join('.'), **net_status[:data], raise: true rescue nil
|
12
|
+
net_status
|
13
|
+
end
|
14
|
+
end
|
data/lib/net_status/exception.rb
CHANGED
@@ -1,18 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module NetStatus
|
2
|
+
class Exception < Exception
|
3
|
+
def initialize(net_status={})
|
4
|
+
@net_status = net_status
|
5
|
+
@net_status[:error] ||= :error
|
6
|
+
super()
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def net_status
|
10
|
+
@net_status.dup.tap do |res|
|
11
|
+
res[:data] = (res[:data] || {}).dup
|
12
|
+
res[:data][:backtrace] ||= self.backtrace
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def message
|
17
|
+
net_status_short.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
module Mixin
|
21
|
+
def net_status
|
22
|
+
{ error: :error, code: :exception, message: self.message, data: { backtrace: self.backtrace } }
|
23
|
+
end
|
24
|
+
|
25
|
+
def net_status_short
|
26
|
+
net_status.dup.tap do |res|
|
27
|
+
if res[:data]
|
28
|
+
res[:data] = res[:data].dup
|
29
|
+
res[:data].delete(:backtrace)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
17
34
|
end
|
18
35
|
end
|
36
|
+
|
37
|
+
::Exception.send(:include, NetStatus::Exception::Mixin)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NetStatus
|
2
|
+
class Hash
|
3
|
+
module Mixin
|
4
|
+
def net_status_normalize(**kwargs)
|
5
|
+
NetStatus.normalize(self, **kwargs)
|
6
|
+
end
|
7
|
+
|
8
|
+
def net_status_error?
|
9
|
+
not net_status_ok?
|
10
|
+
end
|
11
|
+
|
12
|
+
def net_status_ok?
|
13
|
+
!(key? :error)
|
14
|
+
end
|
15
|
+
|
16
|
+
def net_status_ok!
|
17
|
+
raise NetStatus::Exception, self unless net_status_ok?
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
::Hash.send(:include, NetStatus::Hash::Mixin)
|
25
|
+
|
26
|
+
|
data/lib/net_status/version.rb
CHANGED
data/net_status.gemspec
CHANGED
@@ -19,8 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.required_ruby_version = '>= 2.2.1'
|
21
21
|
|
22
|
+
spec.add_dependency 'i18n', '~> 0.7'
|
23
|
+
|
22
24
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
26
|
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
25
27
|
spec.add_development_dependency 'travis', '~> 1.8', '>= 1.8.2'
|
28
|
+
spec.add_development_dependency 'pry', '>= 0.10.3', '< 1.0'
|
26
29
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net_status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Igrychev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +92,26 @@ dependencies:
|
|
78
92
|
- - ! '>='
|
79
93
|
- !ruby/object:Gem::Version
|
80
94
|
version: 1.8.2
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: pry
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.10.3
|
102
|
+
- - <
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.10.3
|
112
|
+
- - <
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '1.0'
|
81
115
|
description: Net status return codes.
|
82
116
|
email:
|
83
117
|
- alexey.igrychev@flant.ru
|
@@ -88,12 +122,13 @@ files:
|
|
88
122
|
- .gitignore
|
89
123
|
- .travis.yml
|
90
124
|
- Gemfile
|
125
|
+
- Gemfile.lock
|
91
126
|
- LICENSE.txt
|
92
127
|
- README.md
|
93
128
|
- Rakefile
|
94
129
|
- lib/net_status.rb
|
95
130
|
- lib/net_status/exception.rb
|
96
|
-
- lib/net_status/
|
131
|
+
- lib/net_status/hash.rb
|
97
132
|
- lib/net_status/version.rb
|
98
133
|
- net_status.gemspec
|
99
134
|
- spec/net_status_spec.rb
|
data/lib/net_status/mixin.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module NetStatus::Exception::Mixin
|
2
|
-
def net_status
|
3
|
-
{ error: :error, code: :exception, message: self.message, data: { backtrace: self.backtrace } }
|
4
|
-
end
|
5
|
-
|
6
|
-
def net_status_short
|
7
|
-
net_status.dup.tap do |res|
|
8
|
-
if res[:data]
|
9
|
-
res[:data] = res[:data].dup
|
10
|
-
res[:data].delete(:backtrace)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
::Exception.send(:include, NetStatus::Exception::Mixin)
|