class Gearhead::Gearbox
Constants
- AfterLoadEvent
- BeforeLoadEvent
Event that gets triggered on load of Active Admin
Public Class Methods
new()
click to toggle source
# File lib/gearhead/gearbox.rb, line 3 def initialize; end
Public Instance Methods
files()
click to toggle source
# File lib/gearhead/gearbox.rb, line 26 def files load_paths.flatten.compact.uniq.flat_map { |path| Dir["#{path}/**/*.rb"] }.sort end
load!()
click to toggle source
# File lib/gearhead/gearbox.rb, line 17 def load! unless loaded? ActiveSupport::Notifications.publish BeforeLoadEvent, self # before_load hook files.each { |file| load file } # load files ActiveSupport::Notifications.publish AfterLoadEvent, self # after_load hook @@loaded = true end end
load_paths()
click to toggle source
# File lib/gearhead/gearbox.rb, line 30 def load_paths [File.expand_path("app/gears", Rails.root)] end
loaded?()
click to toggle source
# File lib/gearhead/gearbox.rb, line 34 def loaded? @@loaded ||= false end
prepare!()
click to toggle source
# File lib/gearhead/gearbox.rb, line 7 def prepare! ActiveSupport::Dependencies.autoload_paths -= load_paths Rails.application.config.eager_load_paths -= load_paths attach_reloader end
routes(rails_router)
click to toggle source
# File lib/gearhead/gearbox.rb, line 42 def routes(rails_router) load! Router.new(router: rails_router).apply end
setup!()
click to toggle source
# File lib/gearhead/gearbox.rb, line 5 def setup!; end
unload!()
click to toggle source
# File lib/gearhead/gearbox.rb, line 38 def unload! @@loaded = false end
Private Instance Methods
attach_reloader()
click to toggle source
# File lib/gearhead/gearbox.rb, line 49 def attach_reloader Rails.application.config.after_initialize do |app| unload_gearhead = -> { Gearhead.gearbox.unload! } if app.config.reload_classes_only_on_change ActiveSupport::Reloader.to_prepare(prepend: true, &unload_gearhead) else ActiveSupport::Reloader.to_complete(&unload_gearhead) end admin_dirs = {} load_paths.each do |path| admin_dirs[path] = [:rb] end routes_reloader = app.config.file_watcher.new([], admin_dirs) do app.reload_routes! end app.reloaders << routes_reloader ActiveSupport::Reloader.to_prepare do unless Gearhead.gearbox.loaded? routes_reloader.execute_if_updated Gearhead.gearbox.load! end end end end