lita-key-value 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 257372e9468420b3569c6af465d25512effca21a
4
- data.tar.gz: 9dc868fc7a438589453397d99564703625cb2030
3
+ metadata.gz: a43f1b3fe82b602f02b2c5fd9959cc344cc2018c
4
+ data.tar.gz: aa56665e4927ba12e2b48d5aecd53d14af705ff3
5
5
  SHA512:
6
- metadata.gz: 3c2d425fea4f3378cb31a03c50f3ad43a193e01c8c114573a08fe2f5442bb4eb4737cd683495cae0cee8c421de3a4444656bdd417b3670b34ccedb12d768c1cb
7
- data.tar.gz: 5c16594bf5c5fdcfa8cb90074f87ff025a09f9859a30cfa7da91ba94c1584e514ad4fad0a4bb6bc0abef0d8420c568cad9ff7c97d439d88fb6960894def3fa66
6
+ metadata.gz: e6e6e7caf234a9a3eec575fd35fd7259f49121658a7ad8ba9b273ad2a2915cd0b0928d828aa6bebc5a3ffa2e4b68744000e4017fd42bba4605692a65ad4edceb
7
+ data.tar.gz: 55b0926c7e3742e0169366daca6420316ade6dee47b60534dc2aab916899fb024c37879d2074188c49fbf86bab0645c56e085420f3c9f3ea9062a69a09798f68
data/README.md CHANGED
@@ -61,7 +61,14 @@ You: Lita, kv list
61
61
  Lita: google, heart, something.else
62
62
  ```
63
63
 
64
- Keys are restricted to alphanumeric characters, underscores, and periods. Values can contain character.
64
+ Search for keys:
65
+
66
+ ```
67
+ You: Lita, kv search amaninacan
68
+ Lita: amaninacan.amazon.recommendations, hello.amaninacan
69
+ ```
70
+
71
+ By default, keys are restricted to alphanumeric characters, underscores, and periods. Values can contain character.
65
72
 
66
73
  ## License
67
74
 
@@ -27,6 +27,10 @@ module Lita
27
27
  route(/^kv\s+list/i, :list, command: true, help: {
28
28
  "kv list" => "List all keys."
29
29
  })
30
+
31
+ route(/^kv\s+search\s+(#{pattern})/i, :search, command: true, help: {
32
+ "kv search KEY" => "Search for keys containing KEY."
33
+ })
30
34
  end
31
35
 
32
36
  on :loaded, :define_routes
@@ -74,6 +78,19 @@ module Lita
74
78
  end
75
79
  end
76
80
 
81
+ def search(response)
82
+ search_term = response.matches.first.first
83
+ keys = redis.hkeys(REDIS_KEY)
84
+
85
+ matching_keys = keys.select { |key| key.include?(search_term) }
86
+
87
+ if matching_keys.empty?
88
+ response.reply("No matching keys found.")
89
+ else
90
+ response.reply(matching_keys.sort.join(", "))
91
+ end
92
+ end
93
+
77
94
  private
78
95
 
79
96
  def config
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-key-value"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{A Lita handler for storing snippets of text.}
@@ -5,6 +5,7 @@ describe Lita::Handlers::KeyValue, lita_handler: true do
5
5
  it { routes_command("kv get foo").to(:get) }
6
6
  it { routes_command("kv delete foo").to(:delete) }
7
7
  it { routes_command("kv list").to(:list) }
8
+ it { routes_command("kv search foo").to(:search) }
8
9
 
9
10
  it "sets and gets keys" do
10
11
  send_command("kv set foo bar")
@@ -48,6 +49,23 @@ describe Lita::Handlers::KeyValue, lita_handler: true do
48
49
  end
49
50
  end
50
51
 
52
+ describe "#search" do
53
+ it "returns keys containing the search term" do
54
+ send_command("kv set foo bar")
55
+ send_command("kv set bazfoo bar")
56
+ send_command("kv set foobaz bar")
57
+ send_command("kv set blahfoobaz bar")
58
+ send_command("kv set hello.amaninacan lol")
59
+ send_command("kv search foo")
60
+ expect(replies.last).to eq("bazfoo, blahfoobaz, foo, foobaz")
61
+ end
62
+
63
+ it "replies with a warning if there are no matching keys" do
64
+ send_command("kv search foo")
65
+ expect(replies.last).to eq("No matching keys found.")
66
+ end
67
+ end
68
+
51
69
  context "with a custom key handler and normalizer" do
52
70
  before do
53
71
  Lita.config.handlers.key_value.tap do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-key-value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita