activematrix 0.0.3 → 0.0.5

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
  SHA256:
3
- metadata.gz: b1f24e67640b140aef30d970e2ca17366a860914fa34dedb4f6879b84259fb43
4
- data.tar.gz: ab62b7257d5bbb8c29738005ffd2443e96f5837a7a07f0b7263a1c9942bad6ff
3
+ metadata.gz: 8fd68a9263d0fb04aaa3f2d0d3160b26b995e783ebc12fa0cf9d67c0084e3d5b
4
+ data.tar.gz: b282050de6c58f9c470a19f1f17c44f1d6cba0e60b0ee0907e9dd1f82d1395e7
5
5
  SHA512:
6
- metadata.gz: 01c30a4813a0ba61fc39ce2dd920dce535ca0de65154f48e635598268ad9480857376363b63441203c7e0d6abe62af7b2580ea74dff8b5853a3a5afc4712381c
7
- data.tar.gz: 96f2c51f3f6b70df680ca90a8f120abe15675f341c706e99286e728d910c9db8fd4c84a53880cfe178cc794d0472ab3bfca856e2a8caa6c1d3112767dd63b1d4
6
+ metadata.gz: 6f90166bf9f0e25db87953d2a79bfec7ddf04542ff975ddf15602f00fbcad5b0f909be3652b85c97ee771e3aab8aca79bb2e01226d35a59c79ba1ae338f2a722
7
+ data.tar.gz: 969d6efbe9f3a65294b983410c3737939dca5cb281fa52f55baaa8de317151126e9cc245b1a693398819053bad8e40c7391157f00a55f3835b98d178cd4fa0e7
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActiveMatrix::Util
3
+ module ActiveMatrix
4
4
  class AccountDataCache
5
5
  extend ActiveMatrix::Extensions
6
6
  include Enumerable
@@ -26,8 +26,6 @@ module ActiveMatrix::Util
26
26
 
27
27
  def reload!
28
28
  # Clear all cache entries for this account data
29
- return unless cache_available?
30
-
31
29
  if room
32
30
  cache.delete_matched("activematrix:account_data:#{client.mxid}:room:#{room.id}:*")
33
31
  else
@@ -48,7 +46,7 @@ module ActiveMatrix::Util
48
46
  end
49
47
 
50
48
  def key?(key)
51
- cache_available? && cache.exist?(cache_key(key))
49
+ cache.exist?(cache_key(key))
52
50
  end
53
51
 
54
52
  def each(live: false)
@@ -63,7 +61,7 @@ module ActiveMatrix::Util
63
61
  else
64
62
  client.api.set_account_data(client.mxid, key, {})
65
63
  end
66
- cache.delete(cache_key(key)) if cache_available?
64
+ cache.delete(cache_key(key))
67
65
  end
68
66
 
69
67
  def [](key)
@@ -72,8 +70,6 @@ module ActiveMatrix::Util
72
70
  # Track the key whenever it's accessed
73
71
  @tracked_keys.add(key)
74
72
 
75
- return fetch_account_data(key) unless cache_available?
76
-
77
73
  cache.fetch(cache_key(key), expires_in: @cache_time) do
78
74
  fetch_account_data(key)
79
75
  end
@@ -98,14 +94,14 @@ module ActiveMatrix::Util
98
94
  end
99
95
 
100
96
  @tracked_keys.add(key)
101
- cache.write(cache_key(key), value, expires_in: @cache_time) if cache_available?
97
+ cache.write(cache_key(key), value, expires_in: @cache_time)
102
98
  end
103
99
 
104
100
  # Write data without making API call (for sync responses)
105
101
  def write(key, value)
106
102
  key = key.to_s unless key.is_a? String
107
103
  @tracked_keys.add(key)
108
- cache.write(cache_key(key), value, expires_in: @cache_time) if cache_available?
104
+ cache.write(cache_key(key), value, expires_in: @cache_time)
109
105
  end
110
106
 
111
107
  private
@@ -118,10 +114,6 @@ module ActiveMatrix::Util
118
114
  end
119
115
  end
120
116
 
121
- def cache_available?
122
- defined?(::Rails) && ::Rails.respond_to?(:cache) && ::Rails.cache
123
- end
124
-
125
117
  def cache
126
118
  ::Rails.cache
127
119
  end
@@ -233,7 +233,7 @@ module ActiveMatrix
233
233
  end
234
234
 
235
235
  def check_agent_health
236
- @registry.all.each do |entry|
236
+ @registry.find_each do |entry|
237
237
  agent = entry[:record]
238
238
  thread = entry[:thread]
239
239
 
@@ -267,7 +267,7 @@ module ActiveMatrix
267
267
  %w[INT TERM].each do |signal|
268
268
  Signal.trap(signal) do
269
269
  Thread.new { stop_all }.join
270
- exit
270
+ exit # rubocop:disable Rails/Exit
271
271
  end
272
272
  end
273
273
  end
@@ -56,12 +56,12 @@ module ActiveMatrix
56
56
 
57
57
  # Get all agent records
58
58
  def all_records
59
- @agents.values.map { |entry| entry[:record] }
59
+ @agents.values.pluck(:record)
60
60
  end
61
61
 
62
62
  # Get all bot instances
63
63
  def all_instances
64
- @agents.values.map { |entry| entry[:instance] }
64
+ @agents.values.pluck(:instance)
65
65
  end
66
66
 
67
67
  # Check if an agent is running
@@ -46,7 +46,7 @@ module ActiveMatrix
46
46
  raise ArgumentError, 'Homeserver URL must be String or URI' unless @homeserver.is_a?(String) || @homeserver.is_a?(URI)
47
47
 
48
48
  @homeserver = URI.parse("#{'https://' unless @homeserver.start_with? 'http'}#{@homeserver}") unless @homeserver.is_a? URI
49
- @homeserver.path.gsub!(/\/?_matrix\/?/, '') if @homeserver.path =~ /_matrix\/?$/
49
+ @homeserver.path.gsub!(/\/?_matrix\/?/, '') if /_matrix\/?$/.match?(@homeserver.path)
50
50
  raise ArgumentError, 'Please use the base URL for your HS (without /_matrix/)' if @homeserver.path.include? '/_matrix/'
51
51
 
52
52
  @proxy_uri = params.fetch(:proxy_uri, nil)
@@ -101,7 +101,7 @@ module ActiveMatrix
101
101
  logger = ActiveMatrix.logger
102
102
  logger.debug "Resolving #{domain}"
103
103
 
104
- if !port.nil? && !port.empty?
104
+ if port.present?
105
105
  # If the domain is fully qualified according to Matrix (FQDN and port) then skip discovery
106
106
  target_uri = URI("https://#{domain}:#{port}")
107
107
  elsif target == :server
@@ -283,7 +283,7 @@ module ActiveMatrix
283
283
  url = homeserver.dup.tap do |u|
284
284
  u.path = api_to_path(api) + path
285
285
  u.query = [u.query, URI.encode_www_form(options.fetch(:query))].flatten.compact.join('&') if options[:query]
286
- u.query = nil if u.query.nil? || u.query.empty?
286
+ u.query = nil if u.query.blank?
287
287
  end
288
288
 
289
289
  failures = 0
@@ -299,9 +299,9 @@ module ActiveMatrix
299
299
  loc_http = http
300
300
  perform_request = proc do
301
301
  @inflight << loc_http
302
- dur_start = Time.now
302
+ dur_start = Time.zone.now
303
303
  response = loc_http.request req_obj
304
- dur_end = Time.now
304
+ dur_end = Time.zone.now
305
305
  duration = dur_end - dur_start
306
306
  rescue EOFError
307
307
  logger.error 'Socket closed unexpectedly'
@@ -130,9 +130,7 @@ module ActiveMatrix::Bot
130
130
  end
131
131
 
132
132
  # Access settings defined with Base.set
133
- def settings
134
- self.class.settings
135
- end
133
+ delegate :settings, to: :class
136
134
 
137
135
  # Access settings defined with Base.set
138
136
  def self.settings
@@ -255,7 +253,7 @@ module ActiveMatrix::Bot
255
253
  # Can use :DM, :Admin, :Mod
256
254
  # @option params
257
255
  def command(command, desc: nil, notes: nil, only: nil, **params, &)
258
- args = params[:args] || convert_to_lambda(&).parameters.map do |type, name|
256
+ args = params[:args] || convert_to_lambda(&).parameters.filter_map do |type, name|
259
257
  case type
260
258
  when :req
261
259
  name.to_s.upcase
@@ -264,7 +262,7 @@ module ActiveMatrix::Bot
264
262
  when :rest
265
263
  "[#{name.to_s.upcase}...]"
266
264
  end
267
- end.compact.join(' ')
265
+ end.join(' ')
268
266
 
269
267
  logger.debug "Registering command #{command} with args #{args}"
270
268
 
@@ -435,7 +433,7 @@ module ActiveMatrix::Bot
435
433
  end
436
434
 
437
435
  def start_bot(bot_settings, &block)
438
- cl = if homeserver =~ %r{^https?://}
436
+ cl = if %r{^https?://}.match?(homeserver)
439
437
  ActiveMatrix::Client.new homeserver
440
438
  else
441
439
  ActiveMatrix::Client.new_for_domain homeserver
@@ -652,7 +650,7 @@ module ActiveMatrix::Bot
652
650
  logger.error "#{e.class} when handling #{event[:type]}: #{e}\n#{e.backtrace[0, 10].join("\n")}"
653
651
  room.send_notice("Failed to handle event of type #{event[:type]} - #{e}.")
654
652
  rescue StandardError => e
655
- puts e, e.backtrace if settings.respond_to?(:testing?) && settings.testing?
653
+ Rails.logger.debug e, e.backtrace if settings.respond_to?(:testing?) && settings.testing?
656
654
  logger.error "#{e.class} when handling #{event[:type]}: #{e}\n#{e.backtrace[0, 10].join("\n")}"
657
655
  room.send_notice("Failed to handle event of type #{event[:type]} - #{e}.\nMore information is available in the bot logs")
658
656
  ensure
@@ -718,7 +716,7 @@ module ActiveMatrix::Bot
718
716
  logger.error "#{e.class} when handling #{settings.command_prefix}#{command}: #{e}\n#{e.backtrace[0, 10].join("\n")}"
719
717
  room.send_notice("Failed to handle #{command} - #{e}.")
720
718
  rescue StandardError => e
721
- puts e, e.backtrace if settings.respond_to?(:testing?) && settings.testing?
719
+ Rails.logger.debug e, e.backtrace if settings.respond_to?(:testing?) && settings.testing?
722
720
  logger.error "#{e.class} when handling #{settings.command_prefix}#{command}: #{e}\n#{e.backtrace[0, 10].join("\n")}"
723
721
  room.send_notice("Failed to handle #{command} - #{e}.\nMore information is available in the bot logs")
724
722
  ensure
@@ -1,7 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'optparse'
4
+
3
5
  module ActiveMatrix
4
- # Namespace module for Bot framework
5
6
  module Bot
7
+ PARAMS_CONFIG = {} # rubocop:disable Style/MutableConstant Intended
8
+
9
+ class << self
10
+ def parse_arguments!
11
+ parser = OptionParser.new do |op|
12
+ op.on('-s homeserver', 'Specify homeserver') { |val| PARAMS_CONFIG[:homeserver] = val }
13
+
14
+ op.on('-T token', 'Token') { |val| PARAMS_CONFIG[:access_token] = val }
15
+ op.on('-U username', 'Username') { |val| PARAMS_CONFIG[:username] = val }
16
+ op.on('-P password', 'Password') { |val| PARAMS_CONFIG[:password] = val }
17
+
18
+ op.on('-q', 'Disable logging') { PARAMS_CONFIG[:logging] = false }
19
+ op.on('-v', 'Enable verbose output') { PARAMS_CONFIG[:logging] = !(PARAMS_CONFIG[:log_level] = :debug).nil? }
20
+ end
21
+
22
+ begin
23
+ parser.parse!(ARGV.dup)
24
+ rescue StandardError => e
25
+ PARAMS_CONFIG[:optparse_error] = e
26
+ end
27
+
28
+ ActiveMatrix.debug! if ENV['MATRIX_DEBUG'] == '1'
29
+ end
30
+ end
31
+
32
+ class Instance < Base
33
+ set :logging, true
34
+ set :log_level, :info
35
+
36
+ set :app_file, caller_files.first || $PROGRAM_NAME
37
+ set(:run) { File.expand_path($PROGRAM_NAME) == File.expand_path(app_file) }
38
+
39
+ if run? && ARGV.any?
40
+ Bot.parse_arguments!
41
+ error = PARAMS_CONFIG.delete(:optparse_error)
42
+ raise error if error
43
+
44
+ PARAMS_CONFIG.each { |k, v| set k, v }
45
+ end
46
+ end
6
47
  end
7
48
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveMatrix
4
+ # Provides caching functionality for Matrix objects
5
+ # Handles serialization/deserialization to work with Rails.cache
6
+ module Cacheable
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ attr_accessor :cached_at
11
+ end
12
+
13
+ class_methods do
14
+ # Reconstruct object from cached data
15
+ def from_cache(client, data)
16
+ return nil unless data.is_a?(Hash) && data[:_cache_class] == name
17
+
18
+ # Remove cache metadata
19
+ attrs = data.except(:_cache_class, :_cached_at)
20
+
21
+ # Reconstruct based on class type
22
+ case name
23
+ when 'ActiveMatrix::User'
24
+ new(client, attrs[:id], attrs.except(:id))
25
+ when 'ActiveMatrix::Room'
26
+ new(client, attrs[:id], attrs.except(:id))
27
+ else
28
+ new(client, attrs)
29
+ end
30
+ end
31
+ end
32
+
33
+ # Convert object to cacheable hash
34
+ def to_cache
35
+ data = cache_attributes.merge(
36
+ _cache_class: self.class.name,
37
+ _cached_at: Time.current
38
+ )
39
+
40
+ # Ensure we only cache serializable data
41
+ data.deep_stringify_keys
42
+ end
43
+
44
+ # Override in each class to specify what to cache
45
+ def cache_attributes
46
+ if respond_to?(:attributes)
47
+ attributes
48
+ elsif respond_to?(:to_h)
49
+ to_h
50
+ else
51
+ {}
52
+ end
53
+ end
54
+
55
+ # Generate a cache key for this object
56
+ def cache_key(*suffixes)
57
+ base_key = "#{self.class.name.underscore}:#{cache_id}"
58
+ suffixes.any? ? "#{base_key}:#{suffixes.join(':')}" : base_key
59
+ end
60
+
61
+ # Override in each class if ID method is different
62
+ def cache_id
63
+ respond_to?(:id) ? id : object_id
64
+ end
65
+
66
+ # Check if this object was loaded from cache
67
+ def from_cache?
68
+ @cached_at.present?
69
+ end
70
+ end
71
+ end
@@ -165,9 +165,9 @@ module ActiveMatrix
165
165
 
166
166
  # Retrieve an account data helper
167
167
  def account_data
168
- return ActiveMatrix::Util::AccountDataCache.new self if cache == :none
168
+ return ActiveMatrix::AccountDataCache.new self if cache == :none
169
169
 
170
- @account_data ||= ActiveMatrix::Util::AccountDataCache.new self
170
+ @account_data ||= ActiveMatrix::AccountDataCache.new self
171
171
  end
172
172
 
173
173
  # Gets a direct message room for the given user if one exists
@@ -252,7 +252,7 @@ module ActiveMatrix
252
252
  username = username.to_s unless username.is_a?(String)
253
253
  password = password.to_s unless password.is_a?(String)
254
254
 
255
- raise ArgumentError, "Username can't be nil or empty" if username.nil? || username.empty?
255
+ raise ArgumentError, "Username can't be nil or empty" if username.blank?
256
256
  raise ArgumentError, "Password can't be nil or empty" if password.nil? || username.empty?
257
257
 
258
258
  data = api.register(auth: { type: 'm.login.dummy' }, username: username, password: password)
@@ -279,8 +279,8 @@ module ActiveMatrix
279
279
  username = username.to_s unless username.is_a?(String)
280
280
  password = password.to_s unless password.is_a?(String)
281
281
 
282
- raise ArgumentError, "Username can't be nil or empty" if username.nil? || username.empty?
283
- raise ArgumentError, "Password can't be nil or empty" if password.nil? || password.empty?
282
+ raise ArgumentError, "Username can't be nil or empty" if username.blank?
283
+ raise ArgumentError, "Password can't be nil or empty" if password.blank?
284
284
 
285
285
  data = api.login(user: username, password: password)
286
286
  post_authentication(data)
@@ -307,8 +307,8 @@ module ActiveMatrix
307
307
  username = username.to_s unless username.is_a?(String)
308
308
  token = token.to_s unless token.is_a?(String)
309
309
 
310
- raise ArgumentError, "Username can't be nil or empty" if username.nil? || username.empty?
311
- raise ArgumentError, "Token can't be nil or empty" if token.nil? || token.empty?
310
+ raise ArgumentError, "Username can't be nil or empty" if username.blank?
311
+ raise ArgumentError, "Token can't be nil or empty" if token.blank?
312
312
 
313
313
  data = api.login(user: username, token: token, type: 'm.login.token')
314
314
  post_authentication(data)
@@ -344,13 +344,13 @@ module ActiveMatrix
344
344
  data.threepids.each do |obj|
345
345
  obj.instance_eval do
346
346
  def added_at
347
- Time.at(self[:added_at] / 1000)
347
+ Time.zone.at(self[:added_at] / 1000)
348
348
  end
349
349
 
350
350
  def validated_at
351
351
  return unless validated?
352
352
 
353
- Time.at(self[:validated_at] / 1000)
353
+ Time.zone.at(self[:validated_at] / 1000)
354
354
  end
355
355
 
356
356
  def validated?
@@ -639,7 +639,7 @@ module ActiveMatrix
639
639
 
640
640
  data.dig(:rooms, :join)&.each do |room_id, join|
641
641
  room = ensure_room(room_id)
642
- room.instance_variable_set '@prev_batch', join.dig(:timeline, :prev_batch)
642
+ room.instance_variable_set :@prev_batch, join.dig(:timeline, :prev_batch)
643
643
  room.instance_variable_set :@members_loaded, true unless sync_filter.fetch(:room, {}).fetch(:state, {}).fetch(:lazy_load_members, false)
644
644
 
645
645
  join.dig(:account_data, :events)&.each do |account_data|
@@ -1,68 +1,82 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveMatrix
4
- # A generic error raised for issues in the ActiveMatrix
5
- class MatrixError < StandardError
6
- end
4
+ module Errors
5
+ # A generic error raised for issues in the ActiveMatrix
6
+ class MatrixError < StandardError
7
+ end
7
8
 
8
- # An error specialized and raised for failed requests
9
- class MatrixRequestError < MatrixError
10
- attr_reader :code, :data, :httpstatus, :message
11
- alias error message
9
+ # An error specialized and raised for failed requests
10
+ class MatrixRequestError < MatrixError
11
+ attr_reader :code, :data, :httpstatus, :message
12
+ alias error message
12
13
 
13
- def self.class_by_code(code)
14
- code = code.to_i
14
+ def self.class_by_code(code)
15
+ code = code.to_i
15
16
 
16
- return MatrixNotAuthorizedError if code == 401
17
- return MatrixForbiddenError if code == 403
18
- return MatrixNotFoundError if code == 404
19
- return MatrixConflictError if code == 409
20
- return MatrixTooManyRequestsError if code == 429
17
+ return MatrixNotAuthorizedError if code == 401
18
+ return MatrixForbiddenError if code == 403
19
+ return MatrixNotFoundError if code == 404
20
+ return MatrixConflictError if code == 409
21
+ return MatrixTooManyRequestsError if code == 429
21
22
 
22
- MatrixRequestError
23
- end
23
+ MatrixRequestError
24
+ end
24
25
 
25
- def self.new_by_code(data, code)
26
- class_by_code(code).new(data, code)
27
- end
26
+ def self.new_by_code(data, code)
27
+ class_by_code(code).new(data, code)
28
+ end
28
29
 
29
- def initialize(error, status)
30
- @code = error[:errcode]
31
- @httpstatus = status
32
- @message = error[:error]
33
- @data = error.except(:errcode, :error)
30
+ def initialize(error, status)
31
+ @code = error[:errcode]
32
+ @httpstatus = status
33
+ @message = error[:error]
34
+ @data = error.except(:errcode, :error)
34
35
 
35
- super(error[:error])
36
- end
36
+ super(error[:error])
37
+ end
37
38
 
38
- def to_s
39
- "HTTP #{httpstatus} (#{code}): #{message}"
39
+ def to_s
40
+ "HTTP #{httpstatus} (#{code}): #{message}"
41
+ end
40
42
  end
41
- end
42
43
 
43
- class MatrixNotAuthorizedError < MatrixRequestError; end
44
+ class MatrixNotAuthorizedError < MatrixRequestError; end
44
45
 
45
- class MatrixForbiddenError < MatrixRequestError; end
46
+ class MatrixForbiddenError < MatrixRequestError; end
46
47
 
47
- class MatrixNotFoundError < MatrixRequestError; end
48
+ class MatrixNotFoundError < MatrixRequestError; end
48
49
 
49
- class MatrixConflictError < MatrixRequestError; end
50
+ class MatrixConflictError < MatrixRequestError; end
50
51
 
51
- class MatrixTooManyRequestsError < MatrixRequestError; end
52
+ class MatrixTooManyRequestsError < MatrixRequestError; end
52
53
 
53
- # An error raised when errors occur in the connection layer
54
- class MatrixConnectionError < MatrixError
55
- def self.class_by_code(code)
56
- return MatrixTimeoutError if code == 504
54
+ # An error raised when errors occur in the connection layer
55
+ class MatrixConnectionError < MatrixError
56
+ def self.class_by_code(code)
57
+ return MatrixTimeoutError if code == 504
57
58
 
58
- MatrixConnectionError
59
+ MatrixConnectionError
60
+ end
59
61
  end
60
- end
61
62
 
62
- class MatrixTimeoutError < MatrixConnectionError
63
- end
63
+ class MatrixTimeoutError < MatrixConnectionError
64
+ end
64
65
 
65
- # An error raised when the homeserver returns an unexpected response to the client
66
- class MatrixUnexpectedResponseError < MatrixError
66
+ # An error raised when the homeserver returns an unexpected response to the client
67
+ class MatrixUnexpectedResponseError < MatrixError
68
+ end
67
69
  end
70
+
71
+ # Make error classes available at the top level for backward compatibility
72
+ MatrixError = Errors::MatrixError
73
+ MatrixRequestError = Errors::MatrixRequestError
74
+ MatrixNotAuthorizedError = Errors::MatrixNotAuthorizedError
75
+ MatrixForbiddenError = Errors::MatrixForbiddenError
76
+ MatrixNotFoundError = Errors::MatrixNotFoundError
77
+ MatrixConflictError = Errors::MatrixConflictError
78
+ MatrixTooManyRequestsError = Errors::MatrixTooManyRequestsError
79
+ MatrixConnectionError = Errors::MatrixConnectionError
80
+ MatrixTimeoutError = Errors::MatrixTimeoutError
81
+ MatrixUnexpectedResponseError = Errors::MatrixUnexpectedResponseError
68
82
  end
@@ -88,9 +88,7 @@ module ActiveMatrix
88
88
  end
89
89
  end
90
90
 
91
- def [](key)
92
- event[key]
93
- end
91
+ delegate :[], to: :event
94
92
 
95
93
  def to_s
96
94
  "#{event[:type]}: #{event.except(:type).to_json}"
@@ -1,17 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- unless Object.respond_to? :yield_self
4
- class Object
5
- def yield_self
6
- yield(self)
7
- end
8
- end
9
- end
10
-
11
- # Time.current is provided by ActiveSupport
12
-
13
- # Time duration helpers are provided by ActiveSupport
14
-
15
3
  module ActiveMatrix
16
4
  module Extensions
17
5
  def events(*symbols)
@@ -25,7 +13,7 @@ module ActiveMatrix
25
13
  name = sym.to_s
26
14
 
27
15
  initializers << "
28
- @on_#{name} = ActiveMatrix::EventHandlerArray.new
16
+ @on_#{name} = ::ActiveMatrix::EventHandlerArray.new
29
17
  "
30
18
  readers << ":on_#{name}"
31
19
  methods << "
@@ -24,33 +24,4 @@ module ActiveMatrix
24
24
  @logger = logger
25
25
  end
26
26
  end
27
-
28
- class << self
29
- def logger
30
- @logger ||= if defined?(::Rails) && ::Rails.respond_to?(:logger)
31
- ::Rails.logger
32
- else
33
- # Fallback for testing
34
- require 'logger'
35
- ::Logger.new($stdout)
36
- end
37
- end
38
-
39
- def logger=(logger)
40
- @logger = logger
41
- @global_logger = !logger.nil?
42
- end
43
-
44
- def debug!
45
- logger.level = if defined?(::Rails)
46
- :debug
47
- else
48
- ::Logger::DEBUG
49
- end
50
- end
51
-
52
- def global_logger?
53
- @global_logger ||= false
54
- end
55
- end
56
27
  end
@@ -32,7 +32,7 @@ module ActiveMatrix
32
32
 
33
33
  # Get multiple keys at once
34
34
  def get_multi(*keys)
35
- keys.to_h { |key| [key, get(key)] }
35
+ keys.index_with { |key| get(key) }
36
36
  end
37
37
 
38
38
  # Set multiple keys at once
@@ -8,7 +8,7 @@ module ActiveMatrix
8
8
  def initialize(identifier)
9
9
  raise ArgumentError, 'Identifier must be a String' unless identifier.is_a? String
10
10
  raise ArgumentError, 'Identifier is too long' if identifier.size > 255
11
- raise ArgumentError, 'Identifier lacks required data' unless identifier =~ %r{^([@!$+#][^:]+:[^:]+(?::\d+)?)|(\$[A-Za-z0-9+/]+)$}
11
+ raise ArgumentError, 'Identifier lacks required data' unless %r{^([@!$+#][^:]+:[^:]+(?::\d+)?)|(\$[A-Za-z0-9+/]+)$}.match?(identifier)
12
12
 
13
13
  # TODO: Community-as-a-Room / Profile-as-a-Room, in case they're going for room aliases
14
14
  @sigil = identifier[0]
@@ -35,7 +35,6 @@ module ActiveMatrix::Protocols::MSC
35
35
  #
36
36
  # @see Protocols::CS#sync
37
37
  # @see https://github.com/matrix-org/matrix-doc/pull/2108/
38
- # rubocop:disable Metrics/MethodLength
39
38
  def msc2108_sync_sse(since: nil, **params, &on_data)
40
39
  raise ArgumentError, 'Must be given a block accepting two args - data and { event:, id: }' \
41
40
  unless on_data.is_a?(Proc) && on_data.arity == 2
@@ -8,11 +8,5 @@ module ActiveMatrix
8
8
  # Configure Rails.logger as the default logger
9
9
  ActiveMatrix.logger = Rails.logger
10
10
  end
11
-
12
- initializer 'activematrix.configure_cache' do
13
- # Rails cache adapter is automatically used when Rails is detected
14
- require 'active_matrix/util/rails_cache_adapter'
15
- ActiveMatrix::Util::Tinycache.adapter = ActiveMatrix::Util::RailsCacheAdapter
16
- end
17
11
  end
18
12
  end
@@ -23,7 +23,7 @@ module ActiveMatrix
23
23
  module Response
24
24
  def self.new(api, data)
25
25
  if data.is_a? Array
26
- raise ArgumentError, 'Input data was not an array of hashes' unless data.all? { |v| v.is_a? Hash }
26
+ raise ArgumentError, 'Input data was not an array of hashes' unless data.all?(Hash)
27
27
 
28
28
  data.each do |value|
29
29
  Response.new api, value