schlep 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/schlep.rb +20 -5
- data/lib/schlep/version.rb +1 -1
- data/test/schlep_test.rb +35 -16
- metadata +10 -10
data/lib/schlep.rb
CHANGED
@@ -11,6 +11,8 @@ module Schlep
|
|
11
11
|
|
12
12
|
def app
|
13
13
|
@app ||= ""
|
14
|
+
|
15
|
+
sanitize @app
|
14
16
|
end
|
15
17
|
|
16
18
|
def configure
|
@@ -44,9 +46,7 @@ module Schlep
|
|
44
46
|
def hostname
|
45
47
|
@hostname ||= `hostname`
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
@hostname
|
49
|
+
sanitize @hostname
|
50
50
|
end
|
51
51
|
|
52
52
|
def redis
|
@@ -76,11 +76,26 @@ module Schlep
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def serialize_message(message)
|
79
|
-
return message
|
80
|
-
|
79
|
+
return message unless message.is_a? String
|
80
|
+
|
81
|
+
begin
|
82
|
+
JSON.parse message
|
83
|
+
rescue JSON::ParserError
|
84
|
+
message
|
85
|
+
end
|
81
86
|
end
|
82
87
|
|
83
88
|
def timestamp
|
84
89
|
Time.now.to_f
|
85
90
|
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def sanitize(string)
|
95
|
+
string.gsub! /\s/, ""
|
96
|
+
string.gsub! /^[^\w]+|[^\w]+$/, ""
|
97
|
+
string.gsub! /[^\w\.]+/, ":"
|
98
|
+
|
99
|
+
string
|
100
|
+
end
|
86
101
|
end
|
data/lib/schlep/version.rb
CHANGED
data/test/schlep_test.rb
CHANGED
@@ -58,11 +58,6 @@ class SchlepTest < Test::Unit::TestCase
|
|
58
58
|
assert Schlep.hostname.is_a? String
|
59
59
|
end
|
60
60
|
|
61
|
-
should "strip whitespace and newlines" do
|
62
|
-
Schlep.hostname = "test string\n"
|
63
|
-
assert_equal "teststring", Schlep.hostname
|
64
|
-
end
|
65
|
-
|
66
61
|
should "not include a newline from the hostname command" do
|
67
62
|
assert_nil Schlep.hostname =~ /\s/
|
68
63
|
end
|
@@ -123,8 +118,8 @@ class SchlepTest < Test::Unit::TestCase
|
|
123
118
|
end
|
124
119
|
|
125
120
|
context "serialize message" do
|
126
|
-
should "
|
127
|
-
assert_equal
|
121
|
+
should "convert json to a hash" do
|
122
|
+
assert_equal ({ "one" => { "two" => 3 }}),
|
128
123
|
Schlep.serialize_message("{\"one\":{\"two\":3}}")
|
129
124
|
end
|
130
125
|
|
@@ -133,21 +128,16 @@ class SchlepTest < Test::Unit::TestCase
|
|
133
128
|
Schlep.serialize_message("test string")
|
134
129
|
end
|
135
130
|
|
136
|
-
should "
|
137
|
-
assert_equal
|
131
|
+
should "leave arrays alone" do
|
132
|
+
assert_equal [1,2,[3,4]],
|
138
133
|
Schlep.serialize_message([1,2,[3,4]])
|
139
134
|
end
|
140
135
|
|
141
|
-
should "
|
142
|
-
assert_equal
|
136
|
+
should "leave hashes alone" do
|
137
|
+
assert_equal ({ :one => { :two => 3 }}),
|
143
138
|
Schlep.serialize_message({ :one => { :two => 3 }})
|
144
139
|
end
|
145
140
|
|
146
|
-
should "convert an array of hashes to json" do
|
147
|
-
assert_equal "[{\"one\":{\"two\":3}},{\"four\":{\"five\":6}}]",
|
148
|
-
Schlep.serialize_message([{ :one => { :two => 3 }},{ :four => { :five => 6 }}])
|
149
|
-
end
|
150
|
-
|
151
141
|
should "leave integers alone" do
|
152
142
|
assert_equal 123,
|
153
143
|
Schlep.serialize_message(123)
|
@@ -164,4 +154,33 @@ class SchlepTest < Test::Unit::TestCase
|
|
164
154
|
assert Schlep.timestamp.is_a? Float
|
165
155
|
end
|
166
156
|
end
|
157
|
+
|
158
|
+
# private
|
159
|
+
|
160
|
+
context "sanitize" do
|
161
|
+
should "strip whitespace" do
|
162
|
+
assert_equal "teststring",
|
163
|
+
Schlep.send(:sanitize, "test string")
|
164
|
+
end
|
165
|
+
|
166
|
+
should "strip newlines" do
|
167
|
+
assert_equal "test",
|
168
|
+
Schlep.send(:sanitize, "test\n")
|
169
|
+
end
|
170
|
+
|
171
|
+
should "replace special characters with a colon" do
|
172
|
+
assert_equal "a:b:c:d:e",
|
173
|
+
Schlep.send(:sanitize, "a:b/c^d$$e")
|
174
|
+
end
|
175
|
+
|
176
|
+
should "remove special characters at the beginning or end or a string" do
|
177
|
+
assert_equal "test:string",
|
178
|
+
Schlep.send(:sanitize, "$test$string$")
|
179
|
+
end
|
180
|
+
|
181
|
+
should "not replace periods" do
|
182
|
+
assert_equal "a.b.c.d.e",
|
183
|
+
Schlep.send(:sanitize, "a.b.c.d.e")
|
184
|
+
end
|
185
|
+
end
|
167
186
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schlep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70227564106320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70227564106320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: guard-test
|
27
|
-
requirement: &
|
27
|
+
requirement: &70227564105360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70227564105360
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70227564104540 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70227564104540
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shoulda
|
49
|
-
requirement: &
|
49
|
+
requirement: &70227564103280 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70227564103280
|
58
58
|
description: Ruby client for schlep. Schlep provides a simple interface for logging
|
59
59
|
and broadcasting events.
|
60
60
|
email:
|