lita-onewheel-doc 0.1.0 → 1.0.0
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/lib/lita/handlers/onewheel_doc.rb +44 -16
- data/lita-onewheel-doc.gemspec +1 -1
- data/spec/lita/handlers/onewheel_doc_spec.rb +11 -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: decc977034b40bf5eb2e30d28eee02ab48060c2a
|
4
|
+
data.tar.gz: 687983c64a8bb2c4474d7e0bbcb629c86ec1e9d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfbe6ed73a4319c0d6745c7ef2a033d378a4602ac39fa56b2cc1a16aeec70c99a191066d47580de71f6cadfa8a7ef26c7844bf0a1fce9c80b75bae4b12934656
|
7
|
+
data.tar.gz: 05626560bfa0f84c3a858fbf687a24fae976a253e8d105a78b18d175cb4e7e264ee32f77d473c2edd4b648771d9f111523a3f2c57b87f60855b5722cf8fa710d
|
@@ -3,44 +3,72 @@ module Lita
|
|
3
3
|
class OnewheelDoc < Handler
|
4
4
|
REDIS_KEY = 'onewheel-doc'
|
5
5
|
|
6
|
-
route /^docdel\s+([\w\/+_-]+)$/,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
route /^doc$/,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
route /^docdel\s+([\w\/+_-]+)$/,
|
7
|
+
:command_del_key,
|
8
|
+
command: true,
|
9
|
+
help: '!docdel key removes a key'
|
10
|
+
route /^doc\s+([\w\/+_-]+)\s+(.*)$/,
|
11
|
+
:command_add_key,
|
12
|
+
command: true,
|
13
|
+
help: '!doc key_val http:// Add a key using key_val and the http link'
|
14
|
+
route /^doc$/,
|
15
|
+
:command_list_keys,
|
16
|
+
command: true,
|
17
|
+
help: '!doc list all keys'
|
18
|
+
route /^doc\s+(\w+)$/,
|
19
|
+
:command_fetch_key,
|
20
|
+
command: true,
|
21
|
+
help: '!doc key_val fetch the value for key_val'
|
22
|
+
|
23
|
+
def command_add_key(response)
|
16
24
|
key = response.matches[0][0]
|
17
25
|
value = response.matches[0][1]
|
18
26
|
redis.hset(REDIS_KEY, key, value)
|
19
27
|
response.reply "Documented #{key} as #{value}"
|
20
28
|
end
|
21
29
|
|
22
|
-
def
|
30
|
+
def command_fetch_key(response)
|
23
31
|
key = response.matches[0][0]
|
24
32
|
|
25
|
-
|
26
|
-
|
33
|
+
reply = redis.hget(REDIS_KEY, key)
|
34
|
+
|
35
|
+
# If we didn't find an exact key, perform a substring match
|
36
|
+
if reply.nil?
|
37
|
+
reply = get_values_that_start_with_key(key)
|
38
|
+
end
|
39
|
+
response.reply reply
|
27
40
|
end
|
28
41
|
|
29
|
-
def
|
42
|
+
def command_list_keys(response)
|
30
43
|
replies = []
|
31
44
|
|
32
45
|
all = redis.hgetall(REDIS_KEY)
|
33
46
|
all.each do |key, val|
|
34
|
-
replies.push
|
47
|
+
replies.push format_key_val_response(key, val)
|
35
48
|
end
|
36
49
|
response.reply replies.join "\n"
|
37
50
|
end
|
38
51
|
|
39
|
-
def
|
52
|
+
def command_del_key(response)
|
40
53
|
key = response.matches[0][0]
|
41
54
|
y = redis.hdel(REDIS_KEY, key)
|
42
55
|
response.reply "Document deleted: #{key}"
|
43
56
|
end
|
57
|
+
|
58
|
+
def get_values_that_start_with_key(key)
|
59
|
+
values = []
|
60
|
+
all = redis.hgetall(REDIS_KEY)
|
61
|
+
all.each do |all_key, all_val|
|
62
|
+
if all_key =~ /^#{key}/
|
63
|
+
values.push format_key_val_response(all_key, all_val)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
reply = values.join "\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
def format_key_val_response(all_key, all_val)
|
70
|
+
"#{all_key}: #{all_val}"
|
71
|
+
end
|
44
72
|
end
|
45
73
|
|
46
74
|
Lita.register_handler(OnewheelDoc)
|
data/lita-onewheel-doc.gemspec
CHANGED
@@ -5,24 +5,35 @@ describe Lita::Handlers::OnewheelDoc, lita_handler: true do
|
|
5
5
|
send_command 'doc one http://one'
|
6
6
|
expect(replies.last).to eq('Documented one as http://one')
|
7
7
|
end
|
8
|
+
|
8
9
|
it 'gets a document' do
|
9
10
|
send_command 'doc one http://one'
|
10
11
|
send_command 'doc one'
|
11
12
|
expect(replies.last).to eq('http://one')
|
12
13
|
end
|
14
|
+
|
13
15
|
it 'lists documents' do
|
14
16
|
send_command 'doc one http://one'
|
15
17
|
send_command 'doc two http://two'
|
16
18
|
send_command 'doc'
|
17
19
|
expect(replies.last).to eq("one: http://one\ntwo: http://two")
|
18
20
|
end
|
21
|
+
|
19
22
|
it 'documents real urls' do
|
20
23
|
send_command 'doc pachinko-endpoints https://shopigniter.atlassian.net/wiki/display/I5/Pachinko+Endpoints'
|
21
24
|
expect(replies.last).to eq('Documented pachinko-endpoints as https://shopigniter.atlassian.net/wiki/display/I5/Pachinko+Endpoints')
|
22
25
|
end
|
26
|
+
|
23
27
|
it 'deletes documents' do
|
24
28
|
send_command 'doc one http://one'
|
25
29
|
send_command 'docdel one'
|
26
30
|
expect(replies.last).to eq('Document deleted: one')
|
27
31
|
end
|
32
|
+
|
33
|
+
it 'finds by parties key' do
|
34
|
+
send_command 'doc pacone http://one'
|
35
|
+
send_command 'doc pactwo http://two'
|
36
|
+
send_command 'doc pac'
|
37
|
+
expect(replies.last).to eq("pacone: http://one\npactwo: http://two")
|
38
|
+
end
|
28
39
|
end
|