Class: Merb::BootLoader
Direct Known Subclasses
AfterAppLoads, BackgroundServices, BeforeAppLoads, BuildFramework, ChooseAdapter, Cookies, Defaults, Dependencies, DropPidFile, LoadClasses, Logger, MimeTypes, MixinSession, RackUpApplication, ReloadClasses, Router, SetupSession, SetupStubClasses, Templates
Defined Under Namespace
Classes: AfterAppLoads, BackgroundServices, BeforeAppLoads, BuildFramework, ChooseAdapter, Cookies, Defaults, Dependencies, DropPidFile, LoadClasses, Logger, MimeTypes, MixinSession, RackUpApplication, ReloadClasses, Router, SetupSession, SetupStubClasses, Templates
Class Method Summary collapse
-
.after(klass) ⇒ Object
Execute this boot loader after the specified boot loader.
-
.after_app_loads(&block) ⇒ Object
Execute a block of code after the app loads.
-
.before(klass) ⇒ Object
Execute this boot loader before the specified boot loader.
-
.before_app_loads(&block) ⇒ Object
Execute a block of code before the app loads but after dependencies load.
-
.before_master_shutdown(&block) ⇒ Object
Execute a block of code before master process is shut down.
-
.before_worker_shutdown(&block) ⇒ Object
Execute a block of code before worker process is shut down.
-
.default_framework ⇒ Object
Set up the default framework.
-
.finished?(bootloader) ⇒ Boolean
Determines whether or not a specific bootloader has finished yet.
-
.inherited(klass) ⇒ Object
Adds the inheriting class to the list of subclasses in a position specified by the before and after methods.
-
.move_klass(klass, where) ⇒ Object
Move a class that is inside the bootloader to some place in the Array, relative to another class.
-
.run ⇒ Object
Runs all boot loader classes by calling their run methods.
Class Method Details
.after(klass) ⇒ Object
Execute this boot loader after the specified boot loader.
Parameters
- klass<~to_s>
-
The boot loader class after which this boot loader should be run.
Returns
nil
:api: plugin
42 43 44 45 |
# File 'lib/merb-core/bootloader.rb', line 42 def after(klass) move_klass(klass, 1) nil end |
.after_app_loads(&block) ⇒ Object
Execute a block of code after the app loads.
Parameters
- &block
-
A block to be added to the callbacks that will be executed after the app loads.
:api: public
150 151 152 |
# File 'lib/merb-core/bootloader.rb', line 150 def after_app_loads(&block) after_load_callbacks << block end |
.before(klass) ⇒ Object
Execute this boot loader before the specified boot loader.
Parameters
- klass<~to_s>
-
The boot loader class before which this boot loader should be run.
Returns
nil
:api: plugin
57 58 59 60 |
# File 'lib/merb-core/bootloader.rb', line 57 def before(klass) move_klass(klass, 0) nil end |
.before_app_loads(&block) ⇒ Object
Execute a block of code before the app loads but after dependencies load.
Parameters
- &block
-
A block to be added to the callbacks that will be executed before the app loads.
:api: public
162 163 164 |
# File 'lib/merb-core/bootloader.rb', line 162 def before_app_loads(&block) before_load_callbacks << block end |
.before_master_shutdown(&block) ⇒ Object
Execute a block of code before master process is shut down. Only makes sense on platforms where Merb server can use forking.
Parameters
- &block
-
A block to be added to the callbacks that will be executed before master process is shut down.
:api: public
175 176 177 |
# File 'lib/merb-core/bootloader.rb', line 175 def before_master_shutdown(&block) before_master_shutdown_callbacks << block end |
.before_worker_shutdown(&block) ⇒ Object
Execute a block of code before worker process is shut down. Only makes sense on platforms where Merb server can use forking.
Parameters
- &block
-
A block to be added to the callbacks that will be executed before worker process is shut down.
:api: public
188 189 190 |
# File 'lib/merb-core/bootloader.rb', line 188 def before_worker_shutdown(&block) before_worker_shutdown_callbacks << block end |
.default_framework ⇒ Object
Set up the default framework
Returns
nil
:api: plugin
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/merb-core/bootloader.rb', line 125 def default_framework %w[view model helper controller mailer part].each do |component| Merb.push_path(component.to_sym, Merb.root_path("app/#{component}s")) end Merb.push_path(:application, Merb.root_path("app" / "controllers" / "application.rb")) Merb.push_path(:config, Merb.root_path("config"), nil) Merb.push_path(:router, Merb.dir_for(:config), (Merb::Config[:router_file] || "router.rb")) Merb.push_path(:lib, Merb.root_path("lib"), nil) Merb.push_path(:merb_session, Merb.root_path("merb" / "session")) Merb.push_path(:log, Merb.log_path, nil) Merb.push_path(:public, Merb.root_path("public"), nil) Merb.push_path(:stylesheet, Merb.dir_for(:public) / "stylesheets", nil) Merb.push_path(:javascript, Merb.dir_for(:public) / "javascripts", nil) Merb.push_path(:image, Merb.dir_for(:public) / "images", nil) nil end |
.finished?(bootloader) ⇒ Boolean
Determines whether or not a specific bootloader has finished yet.
Parameters
- bootloader<String, Class>
-
The name of the bootloader to check.
Returns
- Boolean
-
Whether or not the bootloader has finished.
:api: private
114 115 116 |
# File 'lib/merb-core/bootloader.rb', line 114 def finished?(bootloader) self.finished.include?(bootloader.to_s) end |
.inherited(klass) ⇒ Object
Adds the inheriting class to the list of subclasses in a position specified by the before and after methods.
Parameters
- klass<Class>
-
The class inheriting from Merb::BootLoader.
Returns
nil
:api: plugin
27 28 29 30 |
# File 'lib/merb-core/bootloader.rb', line 27 def inherited(klass) subclasses << klass.to_s super end |
.move_klass(klass, where) ⇒ Object
Move a class that is inside the bootloader to some place in the Array, relative to another class.
Parameters
- klass<~to_s>
-
The klass to move the bootloader relative to
- where<Integer>
-
0 means insert it before; 1 means insert it after
Returns
nil
:api: private
75 76 77 78 79 80 81 82 |
# File 'lib/merb-core/bootloader.rb', line 75 def move_klass(klass, where) index = Merb::BootLoader.subclasses.index(klass.to_s) if index Merb::BootLoader.subclasses.delete(self.to_s) Merb::BootLoader.subclasses.insert(index + where, self.to_s) end nil end |
.run ⇒ Object
Runs all boot loader classes by calling their run methods.
Returns
nil
:api: plugin
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/merb-core/bootloader.rb', line 90 def run Merb.started = true subklasses = subclasses.dup until subclasses.empty? time = Time.now.to_i bootloader = subclasses.shift Merb.logger.debug!("Loading: #{bootloader}") if Merb.verbose_logging? Object.full_const_get(bootloader).run Merb.logger.debug!("It took: #{Time.now.to_i - time}") if Merb.verbose_logging? self.finished << bootloader end self.subclasses = subklasses nil end |