lita-lunch 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20f8c1391f94c8c6bf391e5f009e5a30b4a81440
4
+ data.tar.gz: 4286b295bc1ec431119404c4bda095b8acb83709
5
+ SHA512:
6
+ metadata.gz: 4acffd11596b755e68d3c85392e9353b74c21c94a8cb72ea3a9ab64d92f4fa91e30a965f518e28732581279c3098621b06de81252945babf9d4bbf240e07c7fc
7
+ data.tar.gz: 013edd1c5b86041143feeb82ab0c23be78fb268ada05080710bae7dc06be9916ffa3700f2ead2ecfe34d8132523c017e0d07bd9d6e6125fe011ec1bae17f0517
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Neil Ang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # lita-lunch
2
+
3
+ [![Build Status](https://travis-ci.org/neilang/lita-lunch.png?branch=master)](https://travis-ci.org/neilang/lita-lunch)
4
+ [![Coverage Status](https://coveralls.io/repos/neilang/lita-lunch/badge.png)](https://coveralls.io/r/neilang/lita-lunch)
5
+
6
+ A lita handler for helping you pick where to go for lunch today!
7
+
8
+ ## Installation
9
+
10
+ Add lita-lunch to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem "lita-lunch"
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ There is no additional configuration.
19
+
20
+ ## Usage
21
+
22
+ First you will to add some of your favorite lunch places:
23
+
24
+ ```
25
+ lita lunch places add the taco hut
26
+ lita lunch places add Korean BBQ
27
+ ```
28
+
29
+ Then you can get a lunch suggestion:
30
+
31
+ ```
32
+ lita lunch suggestion
33
+ where should I go for lunch?
34
+ ```
35
+
36
+ You can list all stored places:
37
+
38
+ ```
39
+ lita lunch places
40
+ ```
41
+
42
+ And remove unwanted places:
43
+
44
+ ```
45
+ lita lunch places remove the taco hut
46
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,44 @@
1
+ module Lita
2
+ module Handlers
3
+ class Lunch < Handler
4
+ REDIS_KEY = 'lunch'
5
+
6
+ route(/^lunch (?:places?\s+)?add\s+(.+)$/i, :add_suggestion, command: true, help: { 'lunch add PLACE' => 'Add a lunch place' })
7
+ route(/^lunch (?:places?\s+)?(?:remove|delete)\s+(.+)$/i, :remove_suggestion, command: true, help: { 'lunch remove PLACE' => 'Remove a lunch place' })
8
+ route(/^lunch places?$/i, :list_suggestions, command: true, help: { 'lunch places' => 'List all the known lunch places' })
9
+ route(/^lunch suggest(?:ion)?$/i, :suggest, command: true, help: { 'lunch suggest' => 'Pick somewhere at random' })
10
+ route(/where should (we|i|they) go for lunch/i, :suggest, command: false)
11
+
12
+ def suggest(response)
13
+ index = Random.rand(redis.llen(REDIS_KEY).nonzero? || 1)
14
+ random = redis.lindex(REDIS_KEY, index) || t('.fallback')
15
+ response.reply t('.suggest', place: random)
16
+ end
17
+
18
+ def list_suggestions(response)
19
+ values = redis.lrange(REDIS_KEY, 0, -1)
20
+ response.reply values.size > 0 ? values.join("\n") : t('.empty')
21
+ end
22
+
23
+ def add_suggestion(response)
24
+ place = response.matches[0][0].strip
25
+ return if place.empty?
26
+ redis.rpush(REDIS_KEY, place)
27
+ response.reply t('.added', place: place)
28
+ end
29
+
30
+ def remove_suggestion(response)
31
+ place = response.matches[0][0].strip
32
+ return if place.empty?
33
+ result = redis.lrem(REDIS_KEY, 0, place)
34
+ response.reply result.nonzero? ? t('.removed', place: place) : t('.unfound')
35
+ end
36
+
37
+ def reset!
38
+ redis.del(REDIS_KEY)
39
+ end
40
+ end
41
+
42
+ Lita.register_handler(Lunch)
43
+ end
44
+ end
data/lib/lita-lunch.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/lunch"
8
+
9
+ Lita::Handlers::Lunch.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-lunch"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["neilang"]
5
+ spec.email = ["neilang@gmail.com"]
6
+ spec.description = "A lita handler for helping you pick where to go for lunch"
7
+ spec.summary = "A lita handler for helping you pick where to go for lunch"
8
+ spec.homepage = ""
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.4"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
26
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,10 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ lunch:
5
+ fallback: "that place you like"
6
+ suggest: "How about %{place}?"
7
+ empty: "None added yet"
8
+ added: "%{place} has been added"
9
+ removed: "%{place} has been removed"
10
+ unfound: "You will need to be more specific"
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Lunch, lita_handler: true do
4
+ before do
5
+ subject.reset!
6
+ end
7
+
8
+ describe 'suggesting a place' do
9
+ it { is_expected.to route_command('lunch suggestion').to(:suggest) }
10
+ it { is_expected.to route_command('lunch suggest').to(:suggest) }
11
+ it { is_expected.to route('where should I go for lunch?').to(:suggest) }
12
+ it { is_expected.to route('where should we go for lunch?').to(:suggest) }
13
+ it { is_expected.to route('where should they go for lunch?').to(:suggest) }
14
+
15
+ it 'suggest when no places have been added' do
16
+ send_command('lunch suggest')
17
+ expect(replies.last).to eq 'How about that place you like?'
18
+ end
19
+
20
+ it 'will use an added place' do
21
+ send_command('lunch place add yolo')
22
+ send_command('lunch suggest')
23
+ expect(replies.last).to eq 'How about yolo?'
24
+ end
25
+
26
+ it 'will not use a removed place' do
27
+ send_command('lunch place add yolo')
28
+ send_command('lunch place remove yolo')
29
+ send_command('lunch suggest')
30
+ expect(replies.last).to eq 'How about that place you like?'
31
+ end
32
+
33
+ it 'will not attempt to remove an empty place' do
34
+ send_command('lunch place remove ')
35
+ expect(replies.last).to eq nil
36
+ end
37
+ end
38
+
39
+ describe 'list all places' do
40
+ it { is_expected.to route_command('lunch places').to(:list_suggestions) }
41
+ it { is_expected.to route_command('lunch place').to(:list_suggestions) }
42
+
43
+ it 'tells you if there are no places' do
44
+ send_command('lunch places')
45
+ expect(replies.last).to eq 'None added yet'
46
+ end
47
+
48
+ it 'lists all the known places' do
49
+ send_command('lunch place add foo')
50
+ send_command('lunch place add bar')
51
+ send_command('lunch places')
52
+ expect(replies.last).to eq "foo\nbar"
53
+ end
54
+ end
55
+
56
+ describe 'adding a place' do
57
+ it { is_expected.to route_command('lunch add PLACE').to(:add_suggestion) }
58
+ it { is_expected.to route_command('lunch place add PLACE').to(:add_suggestion) }
59
+ it { is_expected.to route_command('lunch places add PLACE').to(:add_suggestion) }
60
+
61
+ it 'will confirm place added' do
62
+ send_command('lunch place add blah')
63
+ expect(replies.last).to eq 'blah has been added'
64
+ end
65
+
66
+ it 'will not add an empty place' do
67
+ send_command('lunch place add ')
68
+ expect(replies.last).to eq nil
69
+ end
70
+ end
71
+
72
+ describe 'removing a place' do
73
+ it { is_expected.to route_command('lunch remove PLACE').to(:remove_suggestion) }
74
+ it { is_expected.to route_command('lunch delete PLACE').to(:remove_suggestion) }
75
+ it { is_expected.to route_command('lunch place remove PLACE').to(:remove_suggestion) }
76
+ it { is_expected.to route_command('lunch place delete PLACE').to(:remove_suggestion) }
77
+ it { is_expected.to route_command('lunch places remove PLACE').to(:remove_suggestion) }
78
+ it { is_expected.to route_command('lunch places delete PLACE').to(:remove_suggestion) }
79
+
80
+ it 'will confirm place removed' do
81
+ send_command('lunch place add blah')
82
+ send_command('lunch place remove blah')
83
+ expect(replies.last).to eq 'blah has been removed'
84
+ end
85
+
86
+ it 'will confirm if place cannot be found' do
87
+ send_command('lunch place remove yolo')
88
+ expect(replies.last).to eq 'You will need to be more specific'
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-lunch"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-lunch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - neilang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A lita handler for helping you pick where to go for lunch
126
+ email:
127
+ - neilang@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - lib/lita-lunch.rb
139
+ - lib/lita/handlers/lunch.rb
140
+ - lita-lunch.gemspec
141
+ - locales/en.yml
142
+ - spec/lita/handlers/lunch_spec.rb
143
+ - spec/spec_helper.rb
144
+ - templates/.gitkeep
145
+ homepage: ''
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ lita_plugin_type: handler
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.4.5
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: A lita handler for helping you pick where to go for lunch
170
+ test_files:
171
+ - spec/lita/handlers/lunch_spec.rb
172
+ - spec/spec_helper.rb