lita 3.2.0 → 3.3.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: 68d6c55cacef1663c210df90ff03f764bca2c3b3
4
- data.tar.gz: 4696fa739de19bb0a0245fd855666fe6a5622f31
3
+ metadata.gz: 845ed36dd80800a50d3ae7bde6d4a4bf1050beb5
4
+ data.tar.gz: a0c53a123d9ce7f9c62ac9e78f3804c8901df54d
5
5
  SHA512:
6
- metadata.gz: 7701c02aa161e08559b50e1133ea1227cc79d53f4278a772ef274b090fceb9a9bad22a317263f067adfe036a336fc6d3ba6d0a546b014387e12f49cf46d52ec7
7
- data.tar.gz: b4b212cee5587adaf06f0ad8944715b9653a678f041e18d71258bbc4d52864f5cf575c3fb010161325153a42d6bde5271f722202383c5a3ca48b035e2685d204
6
+ metadata.gz: bc1f3239cde3d0997f65a53cfae703f3c361fb5881630bdd4261268560350b953289e8144bebe60d07fecbe68230b71c28316e35afdfd9caac550a3ce69d446e
7
+ data.tar.gz: 0750dc9bf141a7f1b36a23fb4cbf2e04386c7f58757fa0cd72db279ee4b5a3accc9f9d6d3b42a1b1a4b0995930506a6d4f8390f2ba075c49dd960a61f58ffcc1
@@ -1,6 +1,7 @@
1
1
  require "forwardable"
2
2
  require "logger"
3
3
  require "rbconfig"
4
+ require "readline"
4
5
  require "set"
5
6
  require "shellwords"
6
7
  require "thread"
@@ -89,7 +89,7 @@ module Lita
89
89
  # @return [void]
90
90
  # @abstract This should be implemented by the adapter.
91
91
  [:join, :part, :run, :send_messages, :set_topic, :shut_down].each do |method|
92
- define_method(method) do
92
+ define_method(method) do |*_args|
93
93
  Lita.logger.warn(I18n.t("lita.adapter.method_not_implemented", method: method))
94
94
  end
95
95
  end
@@ -43,15 +43,29 @@ module Lita
43
43
  message
44
44
  end
45
45
 
46
+ def normalize_history(input)
47
+ if input == "" || (Readline::HISTORY.size >= 2 && input == Readline::HISTORY[-2])
48
+ Readline::HISTORY.pop
49
+ end
50
+ end
51
+
52
+ def normalize_input(input)
53
+ input.chomp.strip
54
+ end
55
+
56
+ def read_input
57
+ Readline.readline("#{robot.name} > ", true)
58
+ end
59
+
46
60
  def run_loop
47
61
  loop do
48
- print "#{robot.name} > "
49
- input = $stdin.gets
62
+ input = read_input
50
63
  if input.nil?
51
64
  puts
52
65
  break
53
66
  end
54
- input = input.chomp.strip
67
+ input = normalize_input(input)
68
+ normalize_history(input)
55
69
  break if input == "exit" || input == "quit"
56
70
  robot.receive(build_message(input, @source))
57
71
  end
@@ -63,20 +63,26 @@ module Lita
63
63
  def dispatch(robot, message)
64
64
  routes.each do |route|
65
65
  next unless route_applies?(route, message, robot)
66
-
67
66
  log_dispatch(route)
68
-
69
- begin
70
- response = Response.new(message, route.pattern)
71
- Lita.hooks[:trigger_route].each { |hook| hook.call(response: response, route: route) }
72
- new(robot).public_send(route.method_name, response)
73
- rescue Exception => e
74
- log_dispatch_error(e)
75
- raise e if rspec_loaded?
76
- end
67
+ dispatch_to_route(route, robot, message)
77
68
  end
78
69
  end
79
70
 
71
+ # Dispatch directly to a {Route}, ignoring route conditions.
72
+ # @param route [Route] The route to invoke.
73
+ # @param robot [Lita::Robot] The currently running robot.
74
+ # @param message [Lita::Message] The incoming message.
75
+ # @return [void]
76
+ # @since 3.3.0
77
+ def dispatch_to_route(route, robot, message)
78
+ response = Response.new(message, route.pattern)
79
+ Lita.hooks[:trigger_route].each { |hook| hook.call(response: response, route: route) }
80
+ new(robot).public_send(route.method_name, response)
81
+ rescue Exception => e
82
+ log_dispatch_error(e)
83
+ raise e if rspec_loaded?
84
+ end
85
+
80
86
  # Creates a new {Lita::HTTPRoute} which is used to define an HTTP route
81
87
  # for the built-in web server.
82
88
  # @see Lita::HTTPRoute
@@ -157,7 +163,7 @@ module Lita
157
163
 
158
164
  # Determines whether or not an incoming messages should trigger a route.
159
165
  def route_applies?(route, message, robot)
160
- RouteValidator.new(route, message, robot).call
166
+ RouteValidator.new(self, route, message, robot).call
161
167
  end
162
168
 
163
169
  # Checks if RSpec is loaded. If so, assume we are testing and let handler
@@ -9,12 +9,16 @@ module Lita
9
9
 
10
10
  http.get "/lita/info", :web
11
11
 
12
- # Replies with the current version of the Lita.
12
+ # Replies with the current version of Lita, the current version of Redis,
13
+ # and Redis memory usage.
13
14
  # @param response [Lita::Response] The response object.
14
15
  # @return [void]
15
16
  # @since 3.0.0
16
17
  def chat(response)
17
- response.reply "Lita #{Lita::VERSION} - http://www.lita.io/"
18
+ response.reply(
19
+ %(Lita #{Lita::VERSION} - https://www.lita.io/),
20
+ %(Redis #{redis_version} - Memory used: #{redis_memory_usage})
21
+ )
18
22
  end
19
23
 
20
24
  # Returns JSON with basic information about the robot.
@@ -24,13 +28,30 @@ module Lita
24
28
  def web(_request, response)
25
29
  response.headers["Content-Type"] = "application/json"
26
30
  json = MultiJson.dump(
27
- lita_version: Lita::VERSION,
28
31
  adapter: Lita.config.robot.adapter,
29
- robot_name: robot.name,
30
- robot_mention_name: robot.mention_name
32
+ lita_version: Lita::VERSION,
33
+ redis_memory_usage: redis_memory_usage,
34
+ redis_version: redis_version,
35
+ robot_mention_name: robot.mention_name,
36
+ robot_name: robot.name
31
37
  )
32
38
  response.write(json)
33
39
  end
40
+
41
+ # A hash of information about Redis.
42
+ def redis_info
43
+ @redis_info ||= redis.info
44
+ end
45
+
46
+ # The current version of Redis.
47
+ def redis_version
48
+ redis_info["redis_version"]
49
+ end
50
+
51
+ # The amount of memory Redis is using.
52
+ def redis_memory_usage
53
+ redis_info["used_memory_human"]
54
+ end
34
55
  end
35
56
 
36
57
  Lita.register_handler(Info)
@@ -2,6 +2,9 @@ module Lita
2
2
  # Determines if an incoming message should trigger a route.
3
3
  # @api private
4
4
  class RouteValidator
5
+ # The handler class the route belongs to.
6
+ attr_reader :handler
7
+
5
8
  # The incoming message.
6
9
  attr_reader :message
7
10
 
@@ -11,7 +14,8 @@ module Lita
11
14
  # The route being checked.
12
15
  attr_reader :route
13
16
 
14
- def initialize(route, message, robot)
17
+ def initialize(handler, route, message, robot)
18
+ @handler = handler
15
19
  @route = route
16
20
  @message = message
17
21
  @robot = robot
@@ -20,11 +24,11 @@ module Lita
20
24
  # Returns a boolean indicating whether or not the route should be triggered.
21
25
  # @return [Boolean] Whether or not the route should be triggered.
22
26
  def call
23
- return unless passes_route_hooks?(route, message, robot)
24
27
  return unless command_satisfied?(route, message)
25
28
  return if from_self?(message, robot)
26
29
  return unless matches_pattern?(route, message)
27
30
  return unless authorized?(message.user, route.required_groups)
31
+ return unless passes_route_hooks?(route, message, robot)
28
32
 
29
33
  true
30
34
  end
@@ -49,7 +53,7 @@ module Lita
49
53
  # Allow custom route hooks to reject the route
50
54
  def passes_route_hooks?(route, message, robot)
51
55
  Lita.hooks[:validate_route].all? do |hook|
52
- hook.call(route: route, message: message, robot: robot)
56
+ hook.call(handler: handler, route: route, message: message, robot: robot)
53
57
  end
54
58
  end
55
59
 
@@ -9,9 +9,6 @@ end
9
9
  major, *_unused = RSpec::Core::Version::STRING.split(/\./)
10
10
  abort I18n.t("lita.rspec.version_3_required") if major.to_i < 3
11
11
 
12
- major, minor, *_unused = RSpec::Mocks::Version::STRING.split(/\./)
13
- abort I18n.t("lita.rspec.mocks_expect_syntax_required") if major == "2" && minor.to_i < 14
14
-
15
12
  require_relative "rspec/handler"
16
13
 
17
14
  module Lita
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "3.2.0"
3
+ VERSION = "3.3.0"
4
4
  end
@@ -28,11 +28,12 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency "multi_json", ">= 1.7.7"
29
29
  spec.add_runtime_dependency "puma", ">= 2.7.1"
30
30
  spec.add_runtime_dependency "rack", ">= 1.5.2"
31
+ spec.add_runtime_dependency "rb-readline", ">= 0.5.1"
31
32
  spec.add_runtime_dependency "redis-namespace", ">= 1.3.0"
32
33
  spec.add_runtime_dependency "thor", ">= 0.18.1"
33
34
 
34
35
  spec.add_development_dependency "rake"
35
- spec.add_development_dependency "rspec", ">= 3.0.0.beta1"
36
+ spec.add_development_dependency "rspec", ">= 3.0.0"
36
37
  spec.add_development_dependency "simplecov"
37
38
  spec.add_development_dependency "coveralls"
38
39
  spec.add_development_dependency "pry"
@@ -8,14 +8,13 @@ describe Lita::Adapters::Shell do
8
8
  describe "#run" do
9
9
  before do
10
10
  allow(subject).to receive(:puts)
11
- allow(subject).to receive(:print)
12
- allow($stdin).to receive(:gets).and_return("foo", "exit")
11
+ allow(Readline).to receive(:readline).and_return("foo", "exit")
13
12
  allow(robot).to receive(:trigger)
14
13
  allow(robot).to receive(:receive)
15
14
  end
16
15
 
17
16
  it "passes input to the Robot and breaks on an exit message" do
18
- expect(subject).to receive(:print).with("#{robot.name} > ").twice
17
+ expect(Readline).to receive(:readline).with("#{robot.name} > ", true).twice
19
18
  expect(robot).to receive(:receive).with(an_instance_of(Lita::Message))
20
19
  subject.run
21
20
  end
@@ -10,20 +10,56 @@ describe Lita::Handlers::Info, lita_handler: true do
10
10
  describe "#chat" do
11
11
  it "responds with the current version of Lita" do
12
12
  send_command("info")
13
- expect(replies.last).to include(Lita::VERSION)
13
+ expect(replies.first).to include(Lita::VERSION)
14
14
  end
15
15
 
16
16
  it "responds with a link to the website" do
17
17
  send_command("info")
18
- expect(replies.last).to include("lita.io")
18
+ expect(replies.first).to include("lita.io")
19
+ end
20
+
21
+ it "responds with the Redis version and memory usage" do
22
+ send_command("info")
23
+ expect(replies.last).to match(/Redis [\d\.]+ - Memory used: [\d\.]+[BKMG]/)
19
24
  end
20
25
  end
21
26
 
22
27
  describe "#web" do
23
- it "returns JSON with info about the running robot" do
28
+ let(:json) { MultiJson.load(response.body.join) }
29
+
30
+ it "returns JSON" do
24
31
  subject.web(request, response)
25
32
  expect(response.headers["Content-Type"]).to eq("application/json")
26
- expect(response.body.join).to include(%("lita_version":"#{Lita::VERSION}"))
33
+ end
34
+
35
+ it "includes the current version of Lita" do
36
+ subject.web(request, response)
37
+ expect(json).to include("lita_version" => Lita::VERSION)
38
+ end
39
+
40
+ it "includes the adapter being used" do
41
+ subject.web(request, response)
42
+ expect(json).to include("adapter" => Lita.config.robot.adapter.to_s)
43
+ end
44
+
45
+ it "includes the robot's name" do
46
+ subject.web(request, response)
47
+ expect(json).to include("robot_name" => robot.name)
48
+ end
49
+
50
+ it "includes the robot's mention name" do
51
+ subject.web(request, response)
52
+ expect(json).to include("robot_mention_name" => robot.mention_name)
53
+ end
54
+
55
+ it "includes the Redis version" do
56
+ subject.web(request, response)
57
+ expect(json).to have_key("redis_version")
58
+ end
59
+
60
+ it "includes the Redis memory usage" do
61
+ subject.web(request, response)
62
+ expect(json).to have_key("redis_memory_usage")
27
63
  end
28
64
  end
29
65
  end
@@ -14,9 +14,6 @@ require "lita/rspec"
14
14
  RSpec.configure do |config|
15
15
  config.mock_with :rspec do |mocks_config|
16
16
  mocks_config.verify_doubled_constant_names = true
17
- # Enable config option when a new rspec-mocks beta including this patch is released:
18
- # https://github.com/rspec/rspec-mocks/pull/615
19
- #
20
- # mocks_config.verify_partial_doubles = true
17
+ mocks_config.verify_partial_doubles = true
21
18
  end
22
19
  end
@@ -72,7 +72,6 @@ en:
72
72
  rspec:
73
73
  full_suite_required: Lita::RSpec requires both RSpec::Mocks and RSpec::Expectations.
74
74
  version_3_required: RSpec::Core 3 or greater is required to use Lita::RSpec.
75
- mocks_expect_syntax_required: RSpec::Mocks 2.14 or greater is required to use Lita::RSpec.
76
75
  route_failure: |-
77
76
  Expected message "%{message}" to route to :%{route}, but didn't.
78
77
  negative_route_failure: |-
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
20
  spec.add_development_dependency "rake"
21
- spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
21
+ spec.add_development_dependency "rspec", ">= 3.0.0"
22
22
  <%- if config[:coveralls] -%>
23
23
  spec.add_development_dependency "simplecov"
24
24
  spec.add_development_dependency "coveralls"
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: 3.2.0
4
+ version: 3.3.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-05-03 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.5.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: rb-readline
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 0.5.1
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 0.5.1
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: redis-namespace
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +184,14 @@ dependencies:
170
184
  requirements:
171
185
  - - ">="
172
186
  - !ruby/object:Gem::Version
173
- version: 3.0.0.beta1
187
+ version: 3.0.0
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - ">="
179
193
  - !ruby/object:Gem::Version
180
- version: 3.0.0.beta1
194
+ version: 3.0.0
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: simplecov
183
197
  requirement: !ruby/object:Gem::Requirement