Class: Gearhead::Gearbox
- Inherits:
-
Object
- Object
- Gearhead::Gearbox
- Defined in:
- lib/gearhead/gearbox.rb
Constant Summary collapse
- BeforeLoadEvent =
Event that gets triggered on load of Active Admin
"gearbox.application.before_load".freeze
- AfterLoadEvent =
"gearbox.application.after_load".freeze
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize ⇒ Gearbox
constructor
A new instance of Gearbox.
- #load! ⇒ Object
- #load_paths ⇒ Object
- #loaded? ⇒ Boolean
- #prepare! ⇒ Object
- #routes(rails_router) ⇒ Object
- #setup! ⇒ Object
- #unload! ⇒ Object
Constructor Details
#initialize ⇒ Gearbox
Returns a new instance of Gearbox.
3 |
# File 'lib/gearhead/gearbox.rb', line 3 def initialize; end |
Instance Method Details
#files ⇒ Object
26 27 28 |
# File 'lib/gearhead/gearbox.rb', line 26 def files load_paths.flatten.compact.uniq.flat_map { |path| Dir["#{path}/**/*.rb"] }.sort end |
#load! ⇒ Object
17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/gearhead/gearbox.rb', line 30 def load_paths [File.("app/gears", Rails.root)] end |
#loaded? ⇒ Boolean
34 35 36 |
# File 'lib/gearhead/gearbox.rb', line 34 def loaded? @@loaded ||= false end |
#prepare! ⇒ Object
7 8 9 10 11 |
# 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) ⇒ Object
42 43 44 45 |
# File 'lib/gearhead/gearbox.rb', line 42 def routes(rails_router) load! Router.new(router: rails_router).apply end |
#setup! ⇒ Object
5 |
# File 'lib/gearhead/gearbox.rb', line 5 def setup!; end |
#unload! ⇒ Object
38 39 40 |
# File 'lib/gearhead/gearbox.rb', line 38 def unload! @@loaded = false end |