jsender 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/lib/jsender/version.rb +1 -1
- data/lib/jsender.rb +5 -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: d6a6f7c896c804935eb73e7be0ebf27a41065fef
|
4
|
+
data.tar.gz: 558767f25b6284dfe5a9939ab909641a0bcbe1dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ed92bba9f996ac7d1e2e3b28076411fab1d334c90b96c3e5d5c6816e851b6fd44d3126cd67d6ba0f063375ea6722ad912b2ff63f2c21991fcd6719176692d7
|
7
|
+
data.tar.gz: 109f357e1429d7872873aa1cc63c35b291b3bce9d2f24bb4c15ad202d2de419846d6a98dd62b9679ff417dab6079ac826724a3ec034fb08fa55e7b62df37d3d3
|
data/README.md
CHANGED
@@ -34,6 +34,8 @@ Or install it yourself as:
|
|
34
34
|
return fail('code 5 selected') if code == 5
|
35
35
|
return fail_data({ 'a' => 'A', 'b' => 'B' }) if code == 6
|
36
36
|
return fail('some errors for you', ['d', 'a', 't', 'a']) if code == 7
|
37
|
+
return error if code == 8
|
38
|
+
return error('something went wrong') if code == 9
|
37
39
|
fail
|
38
40
|
end
|
39
41
|
end
|
@@ -64,15 +66,20 @@ Or install it yourself as:
|
|
64
66
|
|
65
67
|
iut.action(7)
|
66
68
|
=> {"status"=>"fail", "data"=>{"result"=>["d", "a", "t", "a"], "notifications"=>["some errors for you"]}}
|
67
|
-
|
68
|
-
iut.action(0)
|
69
|
-
=> {"status"=>"fail", "data"=>{"result"=>nil, "notifications"=>["fail"]}}
|
70
|
-
|
71
69
|
iut.has_data?(result, 'a')
|
72
70
|
=> true
|
73
71
|
iut.has_data?(result, 'z')
|
74
72
|
=> false
|
75
73
|
|
74
|
+
iut.action(0)
|
75
|
+
=> {"status"=>"fail", "data"=>{"result"=>nil, "notifications"=>["fail"]}}
|
76
|
+
|
77
|
+
iut.action(8)
|
78
|
+
=> {"status"=>"error", "message"=>nil}
|
79
|
+
|
80
|
+
iut.action(9)
|
81
|
+
=> {"status"=>"error", "message"=>"something went wrong"}
|
82
|
+
|
76
83
|
result = iut.action(6)
|
77
84
|
iut.notifications_include?(result, "ail")
|
78
85
|
=> true
|
data/lib/jsender/version.rb
CHANGED
data/lib/jsender.rb
CHANGED
@@ -2,11 +2,16 @@ require "jsender/version"
|
|
2
2
|
|
3
3
|
module Jsender
|
4
4
|
def report(status, message, result = nil)
|
5
|
+
return { 'status' => 'error', 'message' => message } if status == 'error'
|
5
6
|
data = compile_data(result)
|
6
7
|
data['notifications'] = message.is_a?(Array) ? message : [ message ]
|
7
8
|
{ 'status' => status, 'data' => data }
|
8
9
|
end
|
9
10
|
|
11
|
+
def error(message = nil)
|
12
|
+
report('error', message)
|
13
|
+
end
|
14
|
+
|
10
15
|
def fail(message = nil, data = nil)
|
11
16
|
message ||= 'fail'
|
12
17
|
report('fail', message, data)
|