Skip to content

Commit

Permalink
Fixes #2, #3 - Search now works anywhere, not just at the beginning.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Aug 27, 2016
1 parent 315fcc3 commit a117293
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/lita/handlers/onewheel_doc.rb
Expand Up @@ -30,7 +30,7 @@ def command_add_key(response)
def command_fetch_key(response)
key = response.matches[0][0]

reply = get_values_that_start_with_key(key)
reply = search_for_key(key)
response.reply reply
end

Expand All @@ -50,15 +50,15 @@ def command_del_key(response)
response.reply "Document deleted: #{key}"
end

def get_values_that_start_with_key(key)
def search_for_key(key)
values = []
all = redis.hgetall(REDIS_KEY)
all.each do |all_key, all_val|
if all_key =~ /^#{key}/
if all_key =~ /#{key}/
values.push format_key_val_response(all_key, all_val)
end
end
reply = values.join "\n"
values.join "\n"
end

def format_key_val_response(all_key, all_val)
Expand Down
4 changes: 2 additions & 2 deletions lita-onewheel-doc.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-doc'
spec.version = '2.0.3'
spec.version = '2.1.0'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = 'Basic key/value store designed for http links.'
Expand All @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'lita', '~> 4.4'
spec.add_runtime_dependency 'lita', '~> 4'

spec.add_development_dependency 'bundler', '~> 1.3'
# spec.add_development_dependency 'pry-byebug', '~> 3.1'
Expand Down
6 changes: 6 additions & 0 deletions spec/lita/handlers/onewheel_doc_spec.rb
Expand Up @@ -37,4 +37,10 @@
expect(replies.last).to eq("pacone: http://one\npactwo: http://two")
end

it 'finds by partial key middle-out' do
send_command 'doc pacone http://one'
send_command 'doc pactwo http://two'
send_command 'doc act'
expect(replies.last).to eq('pactwo: http://two')
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
@@ -1,6 +1,6 @@
require 'simplecov'
require 'coveralls'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
Expand Down

0 comments on commit a117293

Please sign in to comment.