lita 2.3.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 413787eadeaaa5e58440f591d404423c90e7b95d
4
- data.tar.gz: 4114e0ac515a2068a361e4f6fdfcd0103ed27e8a
3
+ metadata.gz: 04046c9229b2303b99d39582d60790888db1e611
4
+ data.tar.gz: 0060005dadcb7608aa33051ed9571455463c3698
5
5
  SHA512:
6
- metadata.gz: 58c0d8117141c1809f73422a581bc7a11693eca37f02234abddb913fc70ce631a5026320a4fdfc09f1ec772eb0501301c656fcf750d7a35a23e85415b7ce8d8d
7
- data.tar.gz: bfb5bc4df0cc27e9d242e30beca7e6ae7683f3655dc29dc7ed575fde39c40e62a0a6b3b84746c826fdf5b48e65e5b1de3ac09fe9bc5ba19eb6e48d4bd23ad108
6
+ metadata.gz: 80caca833d509b65a8015de4f3e5845fc5c0c485f4b02b4d9ce70f3beb351f8cbc05b0bdbcac474be0e3248e53915e459e6f30068becbdb701bbe73ba7df295e
7
+ data.tar.gz: 2c5d02ce8eed3c643dd9e0ef43b0467443ea5382686d36c785d9ebbf319ed0b4583c4d92ae1bec0036d49993c28a464aaf4aa3ae6cec1f55b6005bea1e7821b6
@@ -4,3 +4,7 @@ rvm:
4
4
  script: bundle exec rake
5
5
  before_install:
6
6
  - gem update --system
7
+ notifications:
8
+ webhooks:
9
+ urls:
10
+ - https://lita-freenode.herokuapp.com/travis
@@ -0,0 +1,14 @@
1
+ # Contributing to Lita
2
+
3
+ ## Issues
4
+
5
+ Found a bug in Lita? Open an issue on [GitHub Issues](https://github.com/jimmycuadra/lita/issues). For general questions, feedback, and discussion, please visit [Google Groups](http://groups.google.com/group/litaio) or the `#lita.io` channel on the [Freenode IRC network](https://webchat.freenode.net/).
6
+
7
+ ## Pull requests
8
+
9
+ Ready to submit a pull request? Great! Contributions are most welcome. To get your contributions accepted, make sure:
10
+
11
+ * All the tests pass. Run `rspec`.
12
+ * No code quality warnings are generated by [Cane](https://github.com/square/cane). Run `cane`.
13
+ * Any new code paths you've added are covered by tests.
14
+ * Any new classes or methods you've added have API documentation compatible with [YARD](http://yardoc.org/). If you've significantly changed the behavior of an existing class or method, you should also update any existing API documentation.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Lita
2
2
 
3
- [![Build Status](https://travis-ci.org/jimmycuadra/lita.png)](https://travis-ci.org/jimmycuadra/lita)
3
+ [![Gem Version](https://badge.fury.io/rb/lita.png)](http://badge.fury.io/rb/lita)
4
+ [![Build Status](https://travis-ci.org/jimmycuadra/lita.png?branch=master)](https://travis-ci.org/jimmycuadra/lita)
4
5
  [![Code Climate](https://codeclimate.com/github/jimmycuadra/lita.png)](https://codeclimate.com/github/jimmycuadra/lita)
5
6
  [![Coverage Status](https://coveralls.io/repos/jimmycuadra/lita/badge.png)](https://coveralls.io/r/jimmycuadra/lita)
6
7
 
@@ -21,6 +22,7 @@ Automate your business and have fun with your very own robot companion.
21
22
  * Group-based authorization
22
23
  * Configurable logging
23
24
  * Generators for creating new plugins
25
+ * Built-in process daemonization
24
26
 
25
27
  ## Why?
26
28
 
@@ -210,7 +212,9 @@ route /^echo\s+(.+)/, to: :echo, command: true, restrict_to: [:testers, :committ
210
212
  Each method that is called by a route takes one argument, a `Lita::Response` object. This object has the following useful methods:
211
213
 
212
214
  * `reply` - Sends one or more string messages back to the source of the original message, either a private message or a chat room.
215
+ * `reply_privately` - Sends one or more string messages back to the user who sent the original message, whether it initated in a private message or a chat room.
213
216
  * `matches` - An array of regular expression matches obtained by calling `body_of_message.scan(route_regex)`.
217
+ * `match_data` - A `MatchData` object obtained by calling `route_regex.match(body_of_message)`.
214
218
  * `args` - The user's message as an array of strings, as it would be parsed by `Shellwords.split`. For example, if the message was "Lita: auth add joe committers", calling `args` would return `["add", "joe", "committers"]`. ("auth" is considered the command and so is not included in the arguments.) This is very handy for commands that take arguments in a way similar to how a UNIX shell would work.
215
219
  * `message` - A `Lita::Message` object for the incoming message.
216
220
  * `user` - A `Lita::User` object for the user who sent the message.
@@ -416,9 +420,25 @@ There are a few things worth mentioning when deploying an instance of Lita to He
416
420
 
417
421
  Complete documentation for all of Lita's classes and methods can be found at [rdoc.info](http://rdoc.info/gems/lita/frames).
418
422
 
419
- ## Try it out
423
+ ## Available plugins
420
424
 
421
- You can chat with an instance of Lita on the Freenode IRC network in the channel `#litabot`. The bot's name is also *Litabot*.
425
+ * [Adapters](https://github.com/jimmycuadra/lita/wiki/Adapters)
426
+ * [Handlers](https://github.com/jimmycuadra/lita/wiki/Handlers)
427
+
428
+ If you release a Lita plugin of your own, be sure to add it to one of the above lists!
429
+
430
+ ## Questions, feedback, and discussion
431
+
432
+ * [Google Group](http://groups.google.com/group/litaio)
433
+ * [IRC](https://webchat.freenode.net/) (`#lita.io` on the Freenode network)
434
+
435
+ ## Bug reports
436
+
437
+ * [GitHub Issues](https://github.com/jimmycuadra/lita/issues)
438
+
439
+ ## Contributing
440
+
441
+ See the [contribution guide](https://github.com/jimmycuadra/lita/blob/master/CONTRIBUTING.md).
422
442
 
423
443
  ## History
424
444
 
@@ -10,9 +10,6 @@ require "rack"
10
10
  require "redis-namespace"
11
11
  require "thin"
12
12
 
13
- require "lita/version"
14
- require "lita/config"
15
-
16
13
  # The main namespace for Lita. Provides a global registry of adapters and
17
14
  # handlers, as well as global configuration, logger, and Redis store.
18
15
  module Lita
@@ -93,6 +90,8 @@ module Lita
93
90
  end
94
91
  end
95
92
 
93
+ require "lita/version"
94
+ require "lita/config"
96
95
  require "lita/util"
97
96
  require "lita/logger"
98
97
  require "lita/user"
@@ -51,13 +51,15 @@ module Lita
51
51
  # @param message [Lita::Message] The incoming message.
52
52
  # @return [void]
53
53
  def dispatch(robot, message)
54
- routes.select { |r| route_applies?(r, message, robot) }.each do |route|
54
+ routes.each do |route|
55
+ next unless route_applies?(route, message, robot)
56
+
55
57
  log_dispatch(route)
56
58
 
57
59
  begin
58
60
  new(robot).public_send(
59
61
  route.method_name,
60
- build_response(message, route)
62
+ Response.new(message, route.pattern)
61
63
  )
62
64
  rescue Exception => e
63
65
  log_dispatch_error(e)
@@ -95,11 +97,6 @@ module Lita
95
97
 
96
98
  private
97
99
 
98
- # Builds a response object for an incoming message.
99
- def build_response(message, route)
100
- Response.new(message, matches: message.match(route.pattern))
101
- end
102
-
103
100
  # Determines whether or not an incoming messages should trigger a route.
104
101
  def route_applies?(route, message, robot)
105
102
  # Message must be a command if the route requires a command
@@ -17,7 +17,7 @@ Lists help information for terms or commands that begin with COMMAND.
17
17
  def help(response)
18
18
  output = build_help(response)
19
19
  output = filter_help(output, response)
20
- response.reply output.join("\n")
20
+ response.reply_privately output.join("\n")
21
21
  end
22
22
 
23
23
  private
@@ -68,5 +68,13 @@ module Lita
68
68
  def reply(*strings)
69
69
  @robot.send_messages(source, *strings)
70
70
  end
71
+
72
+ # Replies by sending the given strings back to the user who sent the
73
+ # message directly, even if the message was sent in a room.
74
+ # @param strings [String, Array<String>] The strings to send back.
75
+ # @return [void]
76
+ def reply_privately(*strings)
77
+ @robot.send_messages(Source.new(source.user), *strings)
78
+ end
71
79
  end
72
80
  end
@@ -8,23 +8,47 @@ module Lita
8
8
  # @return [Lita::Message] The message.
9
9
  attr_accessor :message
10
10
 
11
- # An array of matches from running the message against the route pattern.
12
- # @return [Array<String>, Array<Array<String>>] The array of matches.
13
- attr_accessor :matches
11
+ # The pattern the incoming message matched.
12
+ # @return [Regexp] The pattern.
13
+ attr_accessor :pattern
14
14
 
15
15
  # @!method args
16
16
  # @see Lita::Message#args
17
17
  # @!method reply
18
18
  # @see Lita::Message#reply
19
+ # @!method reply_privately
20
+ # @see Lita::Message#reply_privately
19
21
  # @!method user
20
22
  # @see Lita::Message#user
21
- def_delegators :message, :args, :reply, :user, :command?
23
+ def_delegators :message, :args, :reply, :reply_privately, :user, :command?
22
24
 
23
25
  # @param message [Lita::Message] The incoming message.
24
- # @param matches [Array<String>, Array<Array<String>>] The Regexp matches.
25
- def initialize(message, matches: nil)
26
- self.message = message
27
- self.matches = matches
26
+ # @param matches [Regexp] The pattern the incoming message matched.
27
+ def initialize(*args)
28
+ options = args.last.is_a?(Hash) ? args.pop : {}
29
+
30
+ self.message = args[0]
31
+ self.pattern = args[1]
32
+
33
+ if options[:matches]
34
+ Lita.logger.warn <<-WARNING.chomp
35
+ Passing a "matches" option to Response's constructor is deprecated. \
36
+ Use Response.new(message, pattern) instead.
37
+ WARNING
38
+ @matches = options[:matches]
39
+ end
40
+ end
41
+
42
+ # An array of matches from scanning the message against the route pattern.
43
+ # @return [Array<String>, Array<Array<String>>] The array of matches.
44
+ def matches
45
+ @matches ||= message.match(pattern)
46
+ end
47
+
48
+ # A +MatchData+ object from running the pattern against the message body.
49
+ # @return [MatchData] The +MatchData+.
50
+ def match_data
51
+ @match_data ||= pattern.match(message.body) if pattern
28
52
  end
29
53
  end
30
54
  end
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.0"
4
4
  end
@@ -71,4 +71,19 @@ describe Lita::Message do
71
71
  subject.reply("foo", "bar")
72
72
  end
73
73
  end
74
+
75
+ describe "#reply_privately" do
76
+ it "sends strings directly to the source user" do
77
+ subject = described_class.new(
78
+ robot,
79
+ "Hello",
80
+ Lita::Source.new("Carl", "#room")
81
+ )
82
+ expect(robot).to receive(:send_messages) do |source, *strings|
83
+ expect(source.room).to be_nil
84
+ expect(strings).to eq(["foo", "bar"])
85
+ end
86
+ subject.reply_privately("foo", "bar")
87
+ end
88
+ end
74
89
  end
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Response do
4
- subject { described_class.new(message) }
4
+ subject { described_class.new(message, pattern) }
5
5
 
6
6
  let(:message) { double("Lita::Message").as_null_object }
7
+ let(:pattern) { double("Regexp").as_null_object }
7
8
 
8
9
  [:args, :reply, :user, :command?].each do |method|
9
10
  it "delegates :#{method} to #message" do
@@ -11,4 +12,11 @@ describe Lita::Response do
11
12
  subject.public_send(method)
12
13
  end
13
14
  end
15
+
16
+ it "supports the deprecated Response.new(message, matches: matches) API" do
17
+ matches = ["foo"]
18
+ expect(Lita.logger).to receive(:warn)
19
+ subject = described_class.new(message, matches: matches)
20
+ expect(subject.matches).to eq(matches)
21
+ end
14
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.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: 2013-08-25 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -202,6 +202,7 @@ extra_rdoc_files: []
202
202
  files:
203
203
  - .gitignore
204
204
  - .travis.yml
205
+ - CONTRIBUTING.md
205
206
  - Gemfile
206
207
  - LICENSE
207
208
  - README.md