jabber_admin 1.4.0 → 1.5.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
  SHA256:
3
- metadata.gz: 9456a35e8ad22426e8e27ddbd157c614fd92533324c280c3bb11fd235dac31c5
4
- data.tar.gz: 05c3750afd3f862405206eab6a8b25398be58617601831c4d5140e79a381e225
3
+ metadata.gz: 8c4af608b6ed7038365c714cb8ffea5270ccb1138fb7f739d448f53be85e1c99
4
+ data.tar.gz: 0f6a0f5d8d0d43781e3dde3451151e44f0e1acbab6419c25963912d8ca884946
5
5
  SHA512:
6
- metadata.gz: 55b2d011af88ecd7e0d26825de7aae04e95f58b85c341de30f290a8462afe001773263ad60fbf7c0a7cdd22a62853b638dcd31f432e2a5c0cac92a6aeb4c63b5
7
- data.tar.gz: 1059978f0ac40003853bcab9861b1de4f31248184687bacdb8988da5882f2f5636fc614c485caae23cc2538591391c98e8764de80a41b328e01c0a9300feb5ec
6
+ metadata.gz: 516a0761b8f1e98e1eb33047826885beb1e75930cee6c555e2cfb76488f77efdff238aca93a96f140af0cc2e5d043fab7c4c4b6d556b02a4e700c052741dcce8
7
+ data.tar.gz: ef4cc3eaa6d182bf92387f1a995b8ea45c14b77e7a46f1234dc5ae21110cb4f468e2ddec4eb36954075646de929745010fd209b315b8d22aa971b0590c753de5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  * TODO: Replace this bullet point with an actual description of a change.
4
4
 
5
+ ### 1.5.0 (12 January 2025)
6
+
7
+ * Switched to Zeitwerk as autoloader (#16)
8
+
5
9
  ### 1.4.0 (3 January 2025)
6
10
 
7
11
  * Raised minimum supported Ruby/Rails version to 2.7/6.1 (#15)
data/jabber_admin.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_dependency 'activesupport', '>= 6.1'
37
37
  spec.add_dependency 'rest-client', '~> 2.1'
38
+ spec.add_dependency 'zeitwerk', '~> 2.6'
38
39
  end
@@ -3,7 +3,7 @@
3
3
  # The gem version details.
4
4
  module JabberAdmin
5
5
  # The version of the +jabber_admin+ gem
6
- VERSION = '1.4.0'
6
+ VERSION = '1.5.0'
7
7
 
8
8
  class << self
9
9
  # Returns the version of gem as a string.
data/lib/jabber_admin.rb CHANGED
@@ -1,16 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'zeitwerk'
3
4
  require 'active_support/inflector'
4
5
  require 'json'
5
6
  require 'pathname'
6
7
  require 'rest-client'
7
8
 
8
- require 'jabber_admin/exceptions'
9
- require 'jabber_admin/configuration'
10
- require 'jabber_admin/commands'
11
- require 'jabber_admin/api_call'
12
- require 'jabber_admin/version'
13
-
14
9
  # jabber_admin
15
10
  #
16
11
  # This gem allows making API calls to the ejabberd RESTful admin backend. We
@@ -53,96 +48,116 @@ require 'jabber_admin/version'
53
48
  # @example Delete a user from the XMPP service, in fire and forget manner
54
49
  # JabberAdmin.unregister user: 'peter@example.com'
55
50
  module JabberAdmin
51
+ # Configure the relative gem code base location
52
+ root_path = Pathname.new("#{__dir__}/jabber_admin")
53
+
54
+ # Setup a Zeitwerk autoloader instance and configure it
55
+ loader = Zeitwerk::Loader.for_gem
56
+
57
+ # Do not auto load some parts of the gem
58
+ loader.ignore(root_path.join('errors.rb'))
59
+
60
+ # Finish the auto loader configuration
61
+ loader.setup
62
+
63
+ # Load standalone code
64
+ require 'jabber_admin/version'
65
+ require 'jabber_admin/errors'
66
+
67
+ # Make sure to eager load all constants
68
+ loader.eager_load
69
+
56
70
  class << self
57
71
  attr_writer :configuration
58
- end
59
72
 
60
- # A simple getter to the global JabberAdmin configuration structure.
61
- #
62
- # @return [JabberAdmin::Configuration] the global JabberAdmin configuration
63
- def self.configuration
64
- @configuration ||= Configuration.new
65
- end
73
+ # A simple getter to the global JabberAdmin configuration structure.
74
+ #
75
+ # @return [JabberAdmin::Configuration] the global JabberAdmin configuration
76
+ def configuration
77
+ @configuration ||= Configuration.new
78
+ end
66
79
 
67
- # Class method to set and change the global configuration. This is just a
68
- # tapped variant of the +.configuration+ method.
69
- #
70
- # @yield [configuration]
71
- # @yieldparam [JabberAdmin::Configuration] configuration
72
- def self.configure
73
- yield(configuration)
74
- end
80
+ # Class method to set and change the global configuration. This is just a
81
+ # tapped variant of the +.configuration+ method.
82
+ #
83
+ # @yield [configuration]
84
+ # @yieldparam [JabberAdmin::Configuration] configuration
85
+ def configure
86
+ yield(configuration)
87
+ end
75
88
 
76
- # Allow an easy to use DSL on the +JabberAdmin+ module. We support predefined
77
- # (known) commands and unknown ones in bang and non-bang variants. This
78
- # allows maximum flexibility to the user. The bang versions perform the
79
- # response checks and raise in case of issues. The non-bang versions skip
80
- # this checks. For unknown commands the +JabberAdmin::ApiCall+ is directly
81
- # utilized with the method name as command. (Without the trailling bang, when
82
- # it is present)
83
- #
84
- # @param method [Symbol, String, #to_s] the name of the command to run
85
- # @param args [Array<Mixed>] all additional API call payload
86
- # @param kwargs [Hash{Symbol => Mixed}] all additional API call payload
87
- # @return [RestClient::Response] the actual response of the command
88
- def self.method_missing(method, *args, **kwargs)
89
- predefined_command(method).call(
90
- predefined_callable(method), *args, **kwargs
91
- )
92
- rescue NameError
93
- predefined_callable(method).call(method.to_s.chomp('!'), *args, **kwargs)
94
- end
89
+ # Allow an easy to use DSL on the +JabberAdmin+ module. We support
90
+ # predefined (known) commands and unknown ones in bang and non-bang
91
+ # variants. This allows maximum flexibility to the user. The bang versions
92
+ # perform the response checks and raise in case of issues. The non-bang
93
+ # versions skip this checks. For unknown commands the
94
+ # +JabberAdmin::ApiCall+ is directly utilized with the method name as
95
+ # command. (Without the trailling bang, when it is present)
96
+ #
97
+ # @param method [Symbol, String, #to_s] the name of the command to run
98
+ # @param args [Array<Mixed>] all additional API call payload
99
+ # @param kwargs [Hash{Symbol => Mixed}] all additional API call payload
100
+ # @return [RestClient::Response] the actual response of the command
101
+ def method_missing(method, *args, **kwargs)
102
+ predefined_command(method).call(
103
+ predefined_callable(method), *args, **kwargs
104
+ )
105
+ rescue NameError
106
+ predefined_callable(method).call(method.to_s.chomp('!'), *args, **kwargs)
107
+ end
95
108
 
96
- # Try to find the given name as a predefined command. When there is no such
97
- # predefined command, we raise a +NameError+.
98
- #
99
- # @param name [Symbol, String, #to_s] the command name to lookup
100
- # @return [Class] the predefined command class constant
101
- def self.predefined_command(name)
102
- # Remove bangs and build the camel case variant
103
- "JabberAdmin::Commands::#{name.to_s.chomp('!').camelize}".constantize
104
- end
109
+ # Try to find the given name as a predefined command. When there is no such
110
+ # predefined command, we raise a +NameError+.
111
+ #
112
+ # @param name [Symbol, String, #to_s] the command name to lookup
113
+ # @return [Class] the predefined command class constant
114
+ def predefined_command(name)
115
+ # Remove bangs and build the camel case variant
116
+ "JabberAdmin::Commands::#{name.to_s.chomp('!').camelize}".constantize
117
+ end
105
118
 
106
- # Generate a matching API call wrapper for the given command name. When we
107
- # have to deal with a bang version, we pass the bang down to the API call
108
- # instance. Otherwise we just run the regular +#perform+ method on the API
109
- # call instance.
110
- #
111
- # @param name [Symbol, String, #to_s] the command name to match
112
- # @return [Proc] the API call wrapper
113
- def self.predefined_callable(name)
114
- method = name.to_s.end_with?('!') ? 'perform!' : 'perform'
115
- proc do |*args, **kwargs|
116
- if kwargs.empty?
117
- ApiCall.send(method, *args)
118
- else
119
- ApiCall.send(method, *args, **kwargs)
119
+ # Generate a matching API call wrapper for the given command name. When we
120
+ # have to deal with a bang version, we pass the bang down to the API call
121
+ # instance. Otherwise we just run the regular +#perform+ method on the API
122
+ # call instance.
123
+ #
124
+ # @param name [Symbol, String, #to_s] the command name to match
125
+ # @return [Proc] the API call wrapper
126
+ def predefined_callable(name)
127
+ method = name.to_s.end_with?('!') ? 'perform!' : 'perform'
128
+ proc do |*args, **kwargs|
129
+ if kwargs.empty?
130
+ ApiCall.send(method, *args)
131
+ else
132
+ ApiCall.send(method, *args, **kwargs)
133
+ end
120
134
  end
121
135
  end
122
- end
123
136
 
124
- # Determine if a room exists. This is a convenience method for the
125
- # +JabberAdmin::Commands::GetRoomAffiliations+ command, which can be used
126
- # to reliably determine whether a room exists or not.
127
- #
128
- # @param room [String] the name of the room to check
129
- # @return [Boolean] whether the room exists or not
130
- def self.room_exist?(room)
131
- get_room_affiliations!(room: room)
132
- true
133
- rescue JabberAdmin::CommandError => e
134
- raise e unless /room does not exist/.match? e.response.body
135
-
136
- false
137
- end
137
+ # Determine if a room exists. This is a convenience method for the
138
+ # +JabberAdmin::Commands::GetRoomAffiliations+ command, which can be used
139
+ # to reliably determine whether a room exists or not.
140
+ #
141
+ # @param room [String] the name of the room to check
142
+ # @return [Boolean] whether the room exists or not
143
+ def room_exist?(room)
144
+ get_room_affiliations!(room: room)
145
+ true
146
+ rescue JabberAdmin::CommandError => e
147
+ raise e unless /room does not exist/.match? e.response.body
138
148
 
139
- # We support all methods if you ask for. This is our dynamic command approach
140
- # here to support predefined and custom commands in the same namespace.
141
- #
142
- # @param method [String] the method to lookup
143
- # @param include_private [Boolean] allow the lookup of private methods
144
- # @return [Boolean] always +true+
145
- def self.respond_to_missing?(_method, _include_private = false)
146
- true
149
+ false
150
+ end
151
+
152
+ # We support all methods if you ask for. This is our dynamic command
153
+ # approach here to support predefined and custom commands in the same
154
+ # namespace.
155
+ #
156
+ # @param method [String] the method to lookup
157
+ # @param include_private [Boolean] allow the lookup of private methods
158
+ # @return [Boolean] always +true+
159
+ def respond_to_missing?(_method, _include_private = false)
160
+ true
161
+ end
147
162
  end
148
163
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jabber_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Mayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-01-03 00:00:00.000000000 Z
12
+ date: 2025-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: zeitwerk
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.6'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.6'
42
56
  description: Library for the ejabberd RESTful admin API
43
57
  email:
44
58
  - hermann.mayer92@gmail.com
@@ -79,7 +93,6 @@ files:
79
93
  - jabber_admin.gemspec
80
94
  - lib/jabber_admin.rb
81
95
  - lib/jabber_admin/api_call.rb
82
- - lib/jabber_admin/commands.rb
83
96
  - lib/jabber_admin/commands/ban_account.rb
84
97
  - lib/jabber_admin/commands/create_room.rb
85
98
  - lib/jabber_admin/commands/create_room_with_opts.rb
@@ -101,7 +114,7 @@ files:
101
114
  - lib/jabber_admin/commands/unregister.rb
102
115
  - lib/jabber_admin/commands/unsubscribe_room.rb
103
116
  - lib/jabber_admin/configuration.rb
104
- - lib/jabber_admin/exceptions.rb
117
+ - lib/jabber_admin/errors.rb
105
118
  - lib/jabber_admin/version.rb
106
119
  homepage:
107
120
  licenses:
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JabberAdmin
4
- # Contains all predefined commands that are supported.
5
- module Commands; end
6
- end
7
-
8
- # Require all commands from the commands subfolder
9
- Dir[Pathname.new(__dir__).join('commands', '**', '*.rb')].sort.each do |file|
10
- require file
11
- end
File without changes