lita 4.0.4 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b2fd77c82dffdb6d152eb1376f3868be921d97b
4
- data.tar.gz: 4bef398d354e621af17bbff01fee340c4eb98d71
3
+ metadata.gz: 8f7cb3c5b605c35c60bdff103c47df2488814712
4
+ data.tar.gz: 22be31cadc4608c676923ea7253a9a3b6456e5ad
5
5
  SHA512:
6
- metadata.gz: aa9adeded2fa7941d30bd875e5540603eddae8e210bd86a61eec4ef1778972122678ce952c873d28e0bdb9cb2348e9074f76c71dd58fa58f5cb1812edac80126
7
- data.tar.gz: 1d1ac3b548b681b8c22fd0804eb306fe10f23756629a15b215a71e3e276f82855c41108fb57a1247aa57090435e1ec4e375f10fd6b6a4100864a13c79601e296
6
+ metadata.gz: 5f11b1e00ff16c75e0a5c56a7c96b6d658d27ef207444deb2808265471409f5fc5d6c2d3c585b3c56434e8097515ce5eee85f7d02de983979e005a47435e415b
7
+ data.tar.gz: 2bb7b4fd5497735d4e4a78559b26878f4de79e016901bf1c123c56b78fa37bc6d3c1e7b430875fd7fd820f55026b5f66e3d54ac1ee7be13a96c74a7941304eb3
@@ -1,3 +1,5 @@
1
+ AbcSize:
2
+ Enabled: false
1
3
  AlignParameters:
2
4
  Enabled: false
3
5
  AndOr:
@@ -10,8 +12,12 @@ Documentation:
10
12
  Enabled: false
11
13
  DoubleNegation:
12
14
  Enabled: false
15
+ EachWithObject:
16
+ Enabled: false
13
17
  EndAlignment:
14
18
  AlignWith: variable
19
+ GuardClause:
20
+ Enabled: false
15
21
  IndentHash:
16
22
  Enabled: false
17
23
  LineLength:
@@ -20,6 +26,8 @@ MethodLength:
20
26
  Enabled: false
21
27
  NonNilCheck:
22
28
  Enabled: false
29
+ ParameterLists:
30
+ Max: 6
23
31
  RegexpLiteral:
24
32
  Enabled: false
25
33
  RescueException:
data/Rakefile CHANGED
@@ -3,6 +3,6 @@ require "rspec/core/rake_task"
3
3
  require "rubocop/rake_task"
4
4
 
5
5
  RSpec::Core::RakeTask.new
6
- Rubocop::RakeTask.new
6
+ RuboCop::RakeTask.new
7
7
 
8
8
  task default: [:spec, :rubocop]
@@ -117,4 +117,5 @@ require_relative "lita/handlers/authorization"
117
117
  require_relative "lita/handlers/help"
118
118
  require_relative "lita/handlers/info"
119
119
  require_relative "lita/handlers/room"
120
+ require_relative "lita/handlers/users"
120
121
  require_relative "lita/handlers/deprecation_check"
@@ -24,7 +24,7 @@ module Lita
24
24
  # @return [void]
25
25
  def send_messages(_target, strings)
26
26
  strings = Array(strings)
27
- strings.reject! { |string| string.empty? }
27
+ strings.reject!(&:empty?)
28
28
  unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ || !$stdout.tty?
29
29
  strings.map! { |string| "\e[32m#{string}\e[0m" }
30
30
  end
@@ -121,7 +121,7 @@ module Lita
121
121
 
122
122
  def generate_config(name, plugin_type)
123
123
  name, gem_name = normalize_names(name)
124
- constant_name = name.split(/_/).map { |p| p.capitalize }.join
124
+ constant_name = name.split(/_/).map(&:capitalize).join
125
125
  namespace = "#{plugin_type}s"
126
126
  constant_namespace = namespace.capitalize
127
127
  spec_type = plugin_type == "handler" ? "lita_handler" : "lita"
@@ -12,9 +12,9 @@ module Lita
12
12
  # @return [void]
13
13
  # @since 4.0.0
14
14
  # @see Lita::ConfigurationBuilder#config
15
- def config(*args, **kwargs)
16
- if block_given?
17
- configuration_builder.config(*args, **kwargs, &proc)
15
+ def config(*args, **kwargs, &block)
16
+ if block
17
+ configuration_builder.config(*args, **kwargs, &block)
18
18
  else
19
19
  configuration_builder.config(*args, **kwargs)
20
20
  end
@@ -106,13 +106,13 @@ module Lita
106
106
  # @yield A block to be evaluated in the context of the new attribute. Used for
107
107
  # defining nested configuration attributes and validators.
108
108
  # @return [void]
109
- def config(name, types: nil, type: nil, required: false, default: nil)
109
+ def config(name, types: nil, type: nil, required: false, default: nil, &block)
110
110
  attribute = self.class.new
111
111
  attribute.name = name
112
112
  attribute.types = types || type
113
113
  attribute.required = required
114
114
  attribute.value = default
115
- attribute.instance_exec(&proc) if block_given?
115
+ attribute.instance_exec(&block) if block
116
116
 
117
117
  children << attribute
118
118
  end
@@ -129,15 +129,15 @@ module Lita
129
129
  # validation passed.
130
130
  # @yield The code that performs validation.
131
131
  # @return [void]
132
- def validate
133
- validator = proc
132
+ def validate(&block)
133
+ validator = block
134
134
 
135
135
  unless value.nil?
136
136
  error = validator.call(value)
137
137
  raise ValidationError, error if error
138
138
  end
139
139
 
140
- @validator = proc
140
+ @validator = block
141
141
  end
142
142
 
143
143
  # Sets the value of the attribute, raising an error if it is not among the valid types.
@@ -134,7 +134,7 @@ module Lita
134
134
  config :log_level, types: [String, Symbol], default: :info do
135
135
  validate do |value|
136
136
  unless LOG_LEVELS.include?(value.to_s.downcase.strip)
137
- "must be one of: #{LOG_LEVELS.join(", ")}"
137
+ "must be one of: #{LOG_LEVELS.join(', ')}"
138
138
  end
139
139
  end
140
140
  end
@@ -41,12 +41,12 @@ module Lita
41
41
  # @yield The body of the route's callback.
42
42
  # @return [void]
43
43
  # @since 4.0.0
44
- def route(pattern, method_name = nil, **options)
44
+ def route(pattern, method_name = nil, **options, &block)
45
45
  options = default_route_options.merge(options)
46
46
  options[:restrict_to] = options[:restrict_to].nil? ? nil : Array(options[:restrict_to])
47
47
  routes << Route.new(
48
48
  pattern,
49
- Callback.new(method_name || (proc if block_given?)),
49
+ Callback.new(method_name || block),
50
50
  options.delete(:command),
51
51
  options.delete(:restrict_to),
52
52
  options.delete(:help),
@@ -73,11 +73,11 @@ module Lita
73
73
  # @param options [Hash] A set of options passed on to Faraday.
74
74
  # @yield [builder] A Faraday builder object for adding middleware.
75
75
  # @return [Faraday::Connection] The new connection object.
76
- def http(options = {})
76
+ def http(options = {}, &block)
77
77
  options = default_faraday_options.merge(options)
78
78
 
79
- if block_given?
80
- Faraday::Connection.new(nil, options, &proc)
79
+ if block
80
+ Faraday::Connection.new(nil, options, &block)
81
81
  else
82
82
  Faraday::Connection.new(nil, options)
83
83
  end
@@ -35,9 +35,9 @@ module Lita
35
35
  # @yield The body of the event callback.
36
36
  # @return [void]
37
37
  # @since 4.0.0
38
- def on(event_name, method_name_or_callable = nil)
38
+ def on(event_name, method_name_or_callable = nil, &block)
39
39
  event_subscriptions[normalize_event(event_name)] << Callback.new(
40
- method_name_or_callable || (proc if block_given?)
40
+ method_name_or_callable || block
41
41
  )
42
42
  end
43
43
 
@@ -66,7 +66,7 @@ module Lita
66
66
  groups_with_users.select! { |group, _| group == requested_group }
67
67
  end
68
68
  groups_with_users.map do |group, users|
69
- user_names = users.map { |u| u.name }.join(", ")
69
+ user_names = users.map(&:name).join(", ")
70
70
  "#{group}: #{user_names}"
71
71
  end
72
72
  end
@@ -83,7 +83,7 @@ module Lita
83
83
 
84
84
  def valid_group?(response, identifier)
85
85
  unless identifier && @group
86
- response.reply "#{t("format")}: #{robot.name} auth add USER GROUP"
86
+ response.reply "#{t('format')}: #{robot.name} auth add USER GROUP"
87
87
  return
88
88
  end
89
89
 
@@ -10,11 +10,10 @@ module Lita
10
10
  # Warns about handlers using the old +default_config+ method.
11
11
  def check_handlers_for_default_config(_payload)
12
12
  robot.registry.handlers.each do |handler|
13
- if handler.respond_to?(:default_config)
14
- Lita.logger.warn(
15
- I18n.t("lita.config.handler_default_config_deprecated", name: handler.namespace)
16
- )
17
- end
13
+ next unless handler.respond_to?(:default_config)
14
+ Lita.logger.warn(
15
+ I18n.t("lita.config.handler_default_config_deprecated", name: handler.namespace)
16
+ )
18
17
  end
19
18
  end
20
19
  end
@@ -0,0 +1,35 @@
1
+ module Lita
2
+ module Handlers
3
+ # Provides information on Lita users.
4
+ # @since 4.1.0
5
+ class Users
6
+ extend Lita::Handler::ChatRouter
7
+
8
+ route(/^users\s+find\s+(.+)/i, :find, command: true, help: {
9
+ t("help.find_key") => t("help.find_value")
10
+ })
11
+
12
+ # Outputs the name, ID, and mention name of a user matching the search query.
13
+ # @param response [Lita::Response] The response object.
14
+ # @return [void]
15
+ def find(response)
16
+ user = Lita::User.fuzzy_find(response.args[1])
17
+
18
+ if user
19
+ response.reply(formatted_user(user))
20
+ else
21
+ response.reply(t("find_empty_state"))
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # Extract and label the relevant user information.
28
+ def formatted_user(user)
29
+ "#{user.name} (ID: #{user.id}, Mention name: #{user.mention_name})"
30
+ end
31
+ end
32
+
33
+ Lita.register_handler(Users)
34
+ end
35
+ end
@@ -28,8 +28,8 @@ module Lita
28
28
  # @param args [Array] Arbitrary initialization arguments for the middleware.
29
29
  # @yield An optional block to be passed to the constructor of the middleware.
30
30
  # @return [void]
31
- def use(middleware, *args)
32
- @registry << MiddlewareWrapper.new(middleware, args, (proc if block_given?))
31
+ def use(middleware, *args, &block)
32
+ @registry << MiddlewareWrapper.new(middleware, args, block)
33
33
  end
34
34
  end
35
35
  end
@@ -47,8 +47,8 @@ module Lita
47
47
  # @yield The body of the adapter class.
48
48
  # @return [void]
49
49
  # @since 4.0.0
50
- def register_adapter(key, adapter = nil)
51
- adapter = PluginBuilder.new(key, &proc).build_adapter if block_given?
50
+ def register_adapter(key, adapter = nil, &block)
51
+ adapter = PluginBuilder.new(key, &block).build_adapter if block
52
52
 
53
53
  unless adapter.is_a?(Class)
54
54
  raise ArgumentError, I18n.t("lita.core.register_adapter.block_or_class_required")
@@ -67,9 +67,9 @@ module Lita
67
67
  # @yield The body of the handler class.
68
68
  # @return [void]
69
69
  # @since 4.0.0
70
- def register_handler(handler_or_key)
71
- if block_given?
72
- handler = PluginBuilder.new(handler_or_key, &proc).build_handler
70
+ def register_handler(handler_or_key, &block)
71
+ if block
72
+ handler = PluginBuilder.new(handler_or_key, &block).build_handler
73
73
  else
74
74
  handler = handler_or_key
75
75
 
@@ -181,12 +181,12 @@ module Lita
181
181
  begin
182
182
  @server.add_tcp_listener(http_config.host, http_config.port.to_i)
183
183
  rescue Errno::EADDRINUSE, Errno::EACCES => e
184
- Lita.logger.fatal I18n.t(
185
- "lita.http.exception",
186
- message: e.message,
187
- backtrace: e.backtrace.join("\n")
188
- )
189
- abort
184
+ Lita.logger.fatal I18n.t(
185
+ "lita.http.exception",
186
+ message: e.message,
187
+ backtrace: e.backtrace.join("\n")
188
+ )
189
+ abort
190
190
  end
191
191
  @server.min_threads = http_config.min_threads
192
192
  @server.max_threads = http_config.max_threads
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "4.0.4"
3
+ VERSION = "4.1.0"
4
4
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Lita::VERSION
9
9
  spec.authors = ["Jimmy Cuadra"]
10
10
  spec.email = ["jimmy@jimmycuadra.com"]
11
- spec.description = %q(A multi-service chat bot with extendable behavior.)
12
- spec.summary = %q(A multi-service chat bot with extendable behavior.)
11
+ spec.description = "ChatOps for Ruby."
12
+ spec.summary = "ChatOps framework for Ruby. Lita is a robot companion for your chat room."
13
13
  spec.homepage = "https://github.com/jimmycuadra/lita"
14
14
  spec.license = "MIT"
15
15
 
@@ -38,5 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "simplecov"
39
39
  spec.add_development_dependency "coveralls"
40
40
  spec.add_development_dependency "pry"
41
- spec.add_development_dependency "rubocop", "~> 0.21.0"
41
+ spec.add_development_dependency "rubocop", "~> 0.28.0"
42
42
  end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Users, lita_handler: true do
4
+ it { is_expected.to route_command("users find carl").to(:find) }
5
+
6
+ describe "#find" do
7
+ it "finds users by ID" do
8
+ send_command("users find 1")
9
+
10
+ expect(replies.first).to eq("Test User (ID: 1, Mention name: Test User)")
11
+ end
12
+
13
+ it "finds users by name" do
14
+ send_command("users find 'Test User'")
15
+
16
+ expect(replies.first).to eq("Test User (ID: 1, Mention name: Test User)")
17
+ end
18
+
19
+ it "finds users by mention name" do
20
+ Lita::User.create(2, name: "Mr. Pug", mention_name: "carl")
21
+
22
+ send_command("users find carl")
23
+
24
+ expect(replies.first).to eq("Mr. Pug (ID: 2, Mention name: carl)")
25
+ end
26
+
27
+ it "replies with a message when no matches are found" do
28
+ send_command("users find nobody")
29
+
30
+ expect(replies.first).to eq("No matching users found.")
31
+ end
32
+ end
33
+ end
@@ -46,6 +46,11 @@ en:
46
46
  join_value: Makes the robot join the room with room ID ROOM_ID.
47
47
  part_key: part ROOM_ID
48
48
  part_value: Makes the robot part from the room with room ID ROOM_ID.
49
+ users:
50
+ find_empty_state: No matching users found.
51
+ help:
52
+ find_key: users find SEARCH_TERM
53
+ find_value: Find a Lita user by ID, name, or mention name.
49
54
  adapter:
50
55
  method_not_implemented: "This adapter has not implemented #%{method}."
51
56
  missing_configs: "The following keys are required on config.adapter: %{configs}"
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: 4.0.4
4
+ version: 4.1.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-12-09 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -254,15 +254,15 @@ dependencies:
254
254
  requirements:
255
255
  - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: 0.21.0
257
+ version: 0.28.0
258
258
  type: :development
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
- version: 0.21.0
265
- description: A multi-service chat bot with extendable behavior.
264
+ version: 0.28.0
265
+ description: ChatOps for Ruby.
266
266
  email:
267
267
  - jimmy@jimmycuadra.com
268
268
  executables:
@@ -303,6 +303,7 @@ files:
303
303
  - lib/lita/handlers/help.rb
304
304
  - lib/lita/handlers/info.rb
305
305
  - lib/lita/handlers/room.rb
306
+ - lib/lita/handlers/users.rb
306
307
  - lib/lita/http_callback.rb
307
308
  - lib/lita/http_route.rb
308
309
  - lib/lita/logger.rb
@@ -345,6 +346,7 @@ files:
345
346
  - spec/lita/handlers/help_spec.rb
346
347
  - spec/lita/handlers/info_spec.rb
347
348
  - spec/lita/handlers/room_spec.rb
349
+ - spec/lita/handlers/users_spec.rb
348
350
  - spec/lita/logger_spec.rb
349
351
  - spec/lita/message_spec.rb
350
352
  - spec/lita/plugin_builder_spec.rb
@@ -392,10 +394,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
392
394
  version: '0'
393
395
  requirements: []
394
396
  rubyforge_project:
395
- rubygems_version: 2.2.2
397
+ rubygems_version: 2.4.5
396
398
  signing_key:
397
399
  specification_version: 4
398
- summary: A multi-service chat bot with extendable behavior.
400
+ summary: ChatOps framework for Ruby. Lita is a robot companion for your chat room.
399
401
  test_files:
400
402
  - spec/lita/adapter_spec.rb
401
403
  - spec/lita/adapters/shell_spec.rb
@@ -415,6 +417,7 @@ test_files:
415
417
  - spec/lita/handlers/help_spec.rb
416
418
  - spec/lita/handlers/info_spec.rb
417
419
  - spec/lita/handlers/room_spec.rb
420
+ - spec/lita/handlers/users_spec.rb
418
421
  - spec/lita/logger_spec.rb
419
422
  - spec/lita/message_spec.rb
420
423
  - spec/lita/plugin_builder_spec.rb