bixby-common 0.4.11 → 0.4.12
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 +4 -4
- data/VERSION +1 -1
- data/bixby-common.gemspec +2 -2
- data/lib/bixby-common/command_response.rb +13 -6
- data/test/command_response_test.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c42be708d73846920649d7e5d751739ec25457a5
|
4
|
+
data.tar.gz: 75b57b797385e2e5f9f5ecb00d3a95c0340f4286
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f994c619270d896ccb1a26084d4bda47755bdb1bf77453006137503873e68f9aeda766481f4241412855ac8411673e0605bf0b222ad2131f9e487f8923b24ccf
|
7
|
+
data.tar.gz: 74c12adcccc39bb244d26bd3fa41437e159df8c7a81810835f9cf6c56a22baa312c97161f642ab9a99d44b234e8b5be0f232d7a950535eb1d827db55a37a5504
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.12
|
data/bixby-common.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: bixby-common 0.4.
|
5
|
+
# stub: bixby-common 0.4.12 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bixby-common"
|
9
|
-
s.version = "0.4.
|
9
|
+
s.version = "0.4.12"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -6,16 +6,23 @@ class CommandResponse
|
|
6
6
|
|
7
7
|
attr_accessor :status, :stdout, :stderr
|
8
8
|
|
9
|
-
|
9
|
+
SUCCESS = 0
|
10
|
+
UNKNOWN_FAILURE = 255
|
11
|
+
|
12
|
+
# Create a new CommandResponse from the given JsonResponse
|
10
13
|
#
|
11
14
|
# @param [JsonResponse] res
|
12
15
|
#
|
13
16
|
# @return [CommandResponse]
|
14
17
|
def self.from_json_response(res)
|
15
18
|
cr = CommandResponse.new(res.data)
|
16
|
-
if
|
17
|
-
|
18
|
-
|
19
|
+
if res.fail? then
|
20
|
+
if !(res.message.nil? || res.message.empty?) then
|
21
|
+
cr.status ||= UNKNOWN_FAILURE
|
22
|
+
cr.stderr ||= res.message
|
23
|
+
else
|
24
|
+
cr.status ||= UNKNOWN_FAILURE
|
25
|
+
end
|
19
26
|
end
|
20
27
|
return cr
|
21
28
|
end
|
@@ -24,7 +31,7 @@ class CommandResponse
|
|
24
31
|
#
|
25
32
|
# @return [JsonResponse]
|
26
33
|
def to_json_response
|
27
|
-
return JsonResponse.new((
|
34
|
+
return JsonResponse.new((success?() ? "success" : "fail"), nil, self.to_hash)
|
28
35
|
end
|
29
36
|
|
30
37
|
def initialize(params = nil)
|
@@ -39,7 +46,7 @@ class CommandResponse
|
|
39
46
|
end
|
40
47
|
|
41
48
|
def success?
|
42
|
-
@status.to_i ==
|
49
|
+
@status && @status.to_i == SUCCESS
|
43
50
|
end
|
44
51
|
|
45
52
|
def fail?
|
@@ -15,6 +15,11 @@ class TestCommandResponse < TestCase
|
|
15
15
|
assert_kind_of CommandResponse, cr
|
16
16
|
assert_equal 255, cr.status
|
17
17
|
assert_equal "unknown", cr.stderr
|
18
|
+
|
19
|
+
assert_throws(CommandException) do
|
20
|
+
cr.raise!
|
21
|
+
end
|
22
|
+
|
18
23
|
begin
|
19
24
|
cr.raise!
|
20
25
|
rescue CommandException => ex
|
@@ -29,6 +34,16 @@ class TestCommandResponse < TestCase
|
|
29
34
|
assert_equal 0, cr.status
|
30
35
|
assert_equal "foobar", cr.stdout
|
31
36
|
assert_nil cr.stderr
|
37
|
+
|
38
|
+
# empty failure message
|
39
|
+
res = JsonResponse.new("fail")
|
40
|
+
assert res.fail?
|
41
|
+
refute res.success?
|
42
|
+
cr = CommandResponse.from_json_response(res)
|
43
|
+
refute cr.success?
|
44
|
+
assert cr.fail?
|
45
|
+
assert cr.error?
|
46
|
+
assert_equal 255, cr.status
|
32
47
|
end
|
33
48
|
|
34
49
|
def test_to_json_response
|