Skip to content

Commit 51e5345

Browse files
authored
DEV: Add lib to autoload path (#130)
Why manually require files when we can autoload? Also update `discourse-rubocop` and resolve new lint violations.
1 parent 610c683 commit 51e5345

File tree

5 files changed

+71
-69
lines changed

5 files changed

+71
-69
lines changed

Gemfile.lock

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,83 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (7.1.3.3)
4+
activesupport (8.0.0)
55
base64
6+
benchmark (>= 0.3)
67
bigdecimal
7-
concurrent-ruby (~> 1.0, >= 1.0.2)
8+
concurrent-ruby (~> 1.0, >= 1.3.1)
89
connection_pool (>= 2.2.5)
910
drb
1011
i18n (>= 1.6, < 2)
12+
logger (>= 1.4.2)
1113
minitest (>= 5.1)
12-
mutex_m
13-
tzinfo (~> 2.0)
14+
securerandom (>= 0.3)
15+
tzinfo (~> 2.0, >= 2.0.5)
16+
uri (>= 0.13.1)
1417
ast (2.4.2)
1518
base64 (0.2.0)
19+
benchmark (0.4.0)
1620
bigdecimal (3.1.8)
17-
concurrent-ruby (1.2.3)
21+
concurrent-ruby (1.3.4)
1822
connection_pool (2.4.1)
1923
drb (2.2.1)
20-
i18n (1.14.5)
24+
i18n (1.14.6)
2125
concurrent-ruby (~> 1.0)
22-
json (2.7.2)
26+
json (2.8.2)
2327
language_server-protocol (3.17.0.3)
24-
minitest (5.23.1)
25-
mutex_m (0.2.0)
26-
parallel (1.24.0)
27-
parser (3.3.1.0)
28+
logger (1.6.1)
29+
minitest (5.25.1)
30+
parallel (1.26.3)
31+
parser (3.3.6.0)
2832
ast (~> 2.4.1)
2933
racc
3034
prettier_print (1.2.1)
31-
racc (1.8.0)
32-
rack (3.0.11)
35+
racc (1.8.1)
36+
rack (3.1.8)
3337
rainbow (3.1.1)
3438
regexp_parser (2.9.2)
35-
rexml (3.3.9)
36-
rubocop (1.64.0)
39+
rubocop (1.68.0)
3740
json (~> 2.3)
3841
language_server-protocol (>= 3.17.0)
3942
parallel (~> 1.10)
4043
parser (>= 3.3.0.2)
4144
rainbow (>= 2.2.2, < 4.0)
42-
regexp_parser (>= 1.8, < 3.0)
43-
rexml (>= 3.2.5, < 4.0)
44-
rubocop-ast (>= 1.31.1, < 2.0)
45+
regexp_parser (>= 2.4, < 3.0)
46+
rubocop-ast (>= 1.32.2, < 2.0)
4547
ruby-progressbar (~> 1.7)
4648
unicode-display_width (>= 2.4.0, < 3.0)
47-
rubocop-ast (1.31.3)
49+
rubocop-ast (1.36.1)
4850
parser (>= 3.3.1.0)
49-
rubocop-capybara (2.20.0)
51+
rubocop-capybara (2.21.0)
5052
rubocop (~> 1.41)
51-
rubocop-discourse (3.8.0)
53+
rubocop-discourse (3.8.6)
5254
activesupport (>= 6.1)
5355
rubocop (>= 1.59.0)
5456
rubocop-capybara (>= 2.0.0)
5557
rubocop-factory_bot (>= 2.0.0)
5658
rubocop-rails (>= 2.25.0)
57-
rubocop-rspec (>= 2.25.0)
58-
rubocop-factory_bot (2.25.1)
59-
rubocop (~> 1.41)
60-
rubocop-rails (2.25.0)
59+
rubocop-rspec (>= 3.0.1)
60+
rubocop-rspec_rails (>= 2.30.0)
61+
rubocop-factory_bot (2.26.1)
62+
rubocop (~> 1.61)
63+
rubocop-rails (2.27.0)
6164
activesupport (>= 4.2.0)
6265
rack (>= 1.1)
63-
rubocop (>= 1.33.0, < 2.0)
66+
rubocop (>= 1.52.0, < 2.0)
6467
rubocop-ast (>= 1.31.1, < 2.0)
65-
rubocop-rspec (2.29.2)
66-
rubocop (~> 1.40)
67-
rubocop-capybara (~> 2.17)
68-
rubocop-factory_bot (~> 2.22)
69-
rubocop-rspec_rails (~> 2.28)
70-
rubocop-rspec_rails (2.28.3)
71-
rubocop (~> 1.40)
68+
rubocop-rspec (3.2.0)
69+
rubocop (~> 1.61)
70+
rubocop-rspec_rails (2.30.0)
71+
rubocop (~> 1.61)
72+
rubocop-rspec (~> 3, >= 3.0.1)
7273
ruby-progressbar (1.13.0)
74+
securerandom (0.3.2)
7375
syntax_tree (6.2.0)
7476
prettier_print (>= 1.2.0)
7577
tzinfo (2.0.6)
7678
concurrent-ruby (~> 1.0)
77-
unicode-display_width (2.5.0)
79+
unicode-display_width (2.6.0)
80+
uri (1.0.2)
7881

7982
PLATFORMS
8083
ruby
@@ -84,4 +87,4 @@ DEPENDENCIES
8487
syntax_tree
8588

8689
BUNDLED WITH
87-
2.5.10
90+
2.5.18

app/controllers/follow/follow_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
class Follow::FollowController < ApplicationController
44
requires_plugin Follow::PLUGIN_NAME
55

6-
FOLLOWING ||= :following
7-
FOLLOWERS ||= :followers
6+
FOLLOWING = :following
7+
FOLLOWERS = :followers
88

99
def index
1010
end

config/routes.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
:defaults => {
1010
format: :json,
1111
}
12+
1213
delete ":username" => "follow#unfollow",
1314
:constraints => {
1415
username: RouteFormat.username,
@@ -17,6 +18,7 @@
1718
:defaults => {
1819
format: :json,
1920
}
21+
2022
get "posts/:username" => "follow#posts",
2123
:constraints => {
2224
username: RouteFormat.username,
@@ -26,3 +28,29 @@
2628
format: :json,
2729
}
2830
end
31+
32+
Discourse::Application.routes.draw do
33+
mount ::Follow::Engine, at: "follow"
34+
35+
%w[users u].each_with_index do |root_path, index|
36+
get "#{root_path}/:username/follow" => "follow/follow#index",
37+
:constraints => {
38+
username: RouteFormat.username,
39+
}
40+
41+
get "#{root_path}/:username/follow/feed" => "follow/follow#index",
42+
:constraints => {
43+
username: RouteFormat.username,
44+
}
45+
46+
get "#{root_path}/:username/follow/following" => "follow/follow#list_following",
47+
:constraints => {
48+
username: RouteFormat.username,
49+
}
50+
51+
get "#{root_path}/:username/follow/followers" => "follow/follow#list_followers",
52+
:constraints => {
53+
username: RouteFormat.username,
54+
}
55+
end
56+
end

lib/follow/engine.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module ::Follow
44
class Engine < ::Rails::Engine
55
engine_name "follow"
66
isolate_namespace Follow
7+
config.autoload_paths << File.join(config.root, "lib")
78
end
89
end

plugin.rb

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,17 @@
1515
register_svg_icon "discourse-follow-new-follower"
1616
register_svg_icon "discourse-follow-new-topic"
1717

18-
require_relative "lib/follow/engine"
19-
20-
Discourse::Application.routes.append do
21-
mount ::Follow::Engine, at: "follow"
22-
%w[users u].each_with_index do |root_path, index|
23-
get "#{root_path}/:username/follow" => "follow/follow#index",
24-
:constraints => {
25-
username: RouteFormat.username,
26-
}
27-
get "#{root_path}/:username/follow/feed" => "follow/follow#index",
28-
:constraints => {
29-
username: RouteFormat.username,
30-
}
31-
32-
get "#{root_path}/:username/follow/following" => "follow/follow#list_following",
33-
:constraints => {
34-
username: RouteFormat.username,
35-
}
36-
get "#{root_path}/:username/follow/followers" => "follow/follow#list_followers",
37-
:constraints => {
38-
username: RouteFormat.username,
39-
}
40-
end
41-
end
42-
4318
module ::Follow
4419
PLUGIN_NAME = "discourse-follow"
4520
end
4621

22+
require_relative "lib/follow/engine"
23+
4724
after_initialize do
4825
Notification.types[:following] = 800
4926
Notification.types[:following_created_topic] = 801
5027
Notification.types[:following_replied] = 802
5128

52-
require_relative "lib/follow/notification"
53-
require_relative "lib/follow/updater"
54-
require_relative "lib/follow/user_extension"
55-
require_relative "lib/follow/notification_handler"
56-
require_relative "app/controllers/follow/follow_controller"
57-
require_relative "config/routes"
58-
5929
reloadable_patch { |plugin| User.prepend(Follow::UserExtension) }
6030

6131
add_to_serializer(:user, :can_see_following) do

0 commit comments

Comments
 (0)