lita-exclusive-route 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/lita-exclusive-route.rb +7 -0
- data/lib/lita/extensions/exclusive_route.rb +21 -0
- data/lita-exclusive-route.gemspec +24 -0
- data/lita-exclusive-route.sublime-project +9 -0
- data/locales/en.yml +4 -0
- data/spec/lita/extensions/exclusive_route_spec.rb +44 -0
- data/spec/spec_helper.rb +10 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e37ad4724a27f45742018a8a9724c479fd4d8305
|
4
|
+
data.tar.gz: 567c8b7c43110824d05209791ef382a82aa96e29
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6fc647e6b78c718c22ec7d77b4800d8634f22d30f17dce260e38c9148af5b25e65c4bd6cf8e2136ffaf96e2a91c294b8d9991605168c954f68cf8be3473f7f1
|
7
|
+
data.tar.gz: 8dd574730166676d149ab28222773fba1cb69c9835416f2bc139518442d46f591b74031ba072ac23c5fe1fcbc8c75af709b4b4a63c2b85cb0a993c85f7a63c75
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Roy Hadrianoro
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# lita-exclusive-route
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/Maysora/lita-exclusive-route.png?branch=master)](https://travis-ci.org/Maysora/lita-exclusive-route)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/Maysora/lita-exclusive-route.png)](https://codeclimate.com/github/Maysora/lita-exclusive-route)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/Maysora/lita-exclusive-route/badge.png?branch=master)](https://coveralls.io/r/Maysora/lita-exclusive-route?branch=master)
|
6
|
+
|
7
|
+
**lita-exclusive-route** is an extension for [Lita](https://www.lita.io/) that allows handler exclusive routes which only trigger when no prior routes already triggered
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add lita-exclusive-route to your Lita plugin's gemspec:
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
spec.add_runtime_dependency "lita-exclusive-route"
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
To make route exclusive simply add `exclusive: true` to it
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# example from lita-responder
|
23
|
+
# this route will catch all chat commands but only if there's no other routes catching it before this
|
24
|
+
route %r{^(.+)$}, :ask_responder, command: true, exclusive: true
|
25
|
+
```
|
26
|
+
|
27
|
+
### Bonus
|
28
|
+
|
29
|
+
It's also possible to get array of routes which caught a chat message by accessing message instance variable :
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# inside handler route callback method
|
33
|
+
response.message.instance_variable_get('@routes') # return array of Lita::Handler::Route triggered before current route
|
34
|
+
```
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Lita
|
2
|
+
module Extensions
|
3
|
+
class ExclusiveRoute
|
4
|
+
def self.call(payload)
|
5
|
+
route = payload[:route]
|
6
|
+
message = payload[:message]
|
7
|
+
|
8
|
+
routes = message.instance_variable_get('@routes') || []
|
9
|
+
if route.extensions[:exclusive] && !routes.empty?
|
10
|
+
false
|
11
|
+
else
|
12
|
+
routes << route
|
13
|
+
message.instance_variable_set('@routes', routes)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Lita.register_hook(:validate_route, ExclusiveRoute)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-exclusive-route"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Roy Hadrianoro"]
|
5
|
+
spec.email = ["dev@maysora.com"]
|
6
|
+
spec.description = %q{A Lita extension to allow exclusive route which only trigger if no prior routes triggered}
|
7
|
+
spec.summary = %q{A Lita extension to allow exclusive route}
|
8
|
+
spec.homepage = "http://www.bocistudio.com"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "extension" }
|
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", ">= 3.3"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
22
|
+
spec.add_development_dependency "simplecov"
|
23
|
+
spec.add_development_dependency "coveralls"
|
24
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class GottaCatchEmAll < Lita::Handler
|
4
|
+
route %r{^Aya\s+Hirano}i, :cute, command: true
|
5
|
+
route %r{^Aya\s+Hirano\s+Cute$}i, :indeed, command: true
|
6
|
+
route %r{^(.+)$}, :catch_all, command: true, exclusive: true
|
7
|
+
|
8
|
+
def cute(response)
|
9
|
+
response.reply('cute')
|
10
|
+
end
|
11
|
+
|
12
|
+
def indeed(response)
|
13
|
+
response.reply('indeed')
|
14
|
+
end
|
15
|
+
|
16
|
+
def catch_all(response)
|
17
|
+
response.reply('Puke-mon!')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe GottaCatchEmAll, lita_handler: true do
|
22
|
+
before do
|
23
|
+
allow(Lita).to receive(:handlers).and_return([described_class])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'trigger cute' do
|
27
|
+
send_command('Aya Hirano')
|
28
|
+
expect(replies.count).to eq(1)
|
29
|
+
expect(replies.last).to eq('cute')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'trigger cute indeed' do
|
33
|
+
send_command('Aya Hirano Cute')
|
34
|
+
expect(replies.count).to eq(2)
|
35
|
+
expect(replies.first).to eq('cute')
|
36
|
+
expect(replies.last).to eq('indeed')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'trigger puke' do
|
40
|
+
send_command('Aya we lah')
|
41
|
+
expect(replies.count).to eq(1)
|
42
|
+
expect(replies.first).to eq('Puke-mon!')
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
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-exclusive-route"
|
10
|
+
require "lita/rspec"
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-exclusive-route
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roy Hadrianoro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-02 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: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
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: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
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: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A Lita extension to allow exclusive route which only trigger if no prior
|
98
|
+
routes triggered
|
99
|
+
email:
|
100
|
+
- dev@maysora.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/lita-exclusive-route.rb
|
112
|
+
- lib/lita/extensions/exclusive_route.rb
|
113
|
+
- lita-exclusive-route.gemspec
|
114
|
+
- lita-exclusive-route.sublime-project
|
115
|
+
- locales/en.yml
|
116
|
+
- spec/lita/extensions/exclusive_route_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
homepage: http://www.bocistudio.com
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata:
|
122
|
+
lita_plugin_type: extension
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A Lita extension to allow exclusive route
|
143
|
+
test_files:
|
144
|
+
- spec/lita/extensions/exclusive_route_spec.rb
|
145
|
+
- spec/spec_helper.rb
|