Class: Gearhead::Gearbox

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeGearbox

Returns a new instance of Gearbox.



3
# File 'lib/gearhead/gearbox.rb', line 3

def initialize; end

Instance Method Details

#filesObject



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_pathsObject



30
31
32
# File 'lib/gearhead/gearbox.rb', line 30

def load_paths
  [File.expand_path("app/gears", Rails.root)]
end

#loaded?Boolean

Returns:

  • (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