What is "reloadable_patch" exactly?

Hey,

Still trying to dissect plugins, I was looking to override TopicsController in my studies and searched the Discourse code repo and noticed reloadable_patch

Then I searched for reloadable_patch in Discourse, and got 12 code hits:

https://github.com/search?p=1&q=org%3Adiscourse+reloadable_patch&type=Code

So, I decided to look more broadly to try to understand this fascinating “method / hook (?)”, so I:

  • Searched all of Github:
    – All results seem to be related to Discourse (plugins)

  • Searched the web
    – All results seem to be related to Discourse (plugins)

  • Searched meta
    – Got a few hits but nothing which explained reloadable_patch (internals) in details.

Next, I searched the Discourse repo again, and could not find (must be because I am not experienced at this) the “definition” of what, exactly reloadable_patch does (or is defined).

It seems, to a Ruby rookie like me, to be a “method” for a lack of a better word, or a “hook” that facilitates overriding Discourse classes; but I could not find the Ruby code which defines how it works, internally.

Does someone mind to explain this to me or point me to the “defining code” which would explain what reloadable_patch does, from a Ruby internals perspective?

Thanks!

Hopefully, I’m not being a PITA to ask !! :slight_smile:

3 Likes

https://github.com/discourse/discourse/blob/232d277833c5e89aef1569b2167436b53f5747bb/lib/plugin/instance.rb#L861

Its defined here. Hope that helps in digging further.

6 Likes

Thanks so much @fzngagan

Not sure why that def method did not show up when I searched the repo with that keyword; but that is exactly what I was looking for!

Thank you again!!

Edit: I see what happened. I did not look into that instance.rb file deep enough and stopped at the top of the file; but there were 23 entries for reloadable_patch in the file, and the def was at the bottom.

A “def reloadable_patch” in quotes search found it (just now) :slight_smile:

I’m starting to get addicted to Ruby, looking into every nook and cranny.

4 Likes

Explained nicely by @markvanlan

7 Likes