Class: Doozer::Initializer
Overview
This is the main class which facilitates booting Doozer components and hooks.
Calling boot initializes Doozer in the following order:
-
Doozer::Configs
-
require ORM
-
require app_path/config/environment.rb
-
call Doozer::Initializer.after_orm_init
-
call Doozer.init_after_orm_gems - initialized in app_path/gems/plugins/init.rb
-
call Doozer.init_after_orm_plugins - initialized in app_path/gems/plugins/init.rb
-
require Doozer::App
-
call Doozer::Initializer.before_rackup_init
Constant Summary collapse
- @@after_orm =
[]
- @@before_rackup =
[]
Class Method Summary collapse
-
.after_orm(&block) ⇒ Object
Primary hook for extending/overriding ORM.
-
.before_rackup(&block) ⇒ Object
Primary hook for adding/overriding Doozer::ViewHelpers methods.
-
.boot(env, app_path = nil) ⇒ Object
env - :development, :deployment, or :test app_path - optional path which overrides where the application is loaded from.
-
.console(env, app_path = nil) ⇒ Object
TODO: test this again.
-
.environment ⇒ Object
Requires the root/config/environment.rb hooks.
-
.orm ⇒ Object
Checks to see if an ORM gem (active_record, data_mapper, or sequel) is specified in database.yml and loads it.
Class Method Details
.after_orm(&block) ⇒ Object
Primary hook for extending/overriding ORM. Code block is pushed onto an array which allows for multiple hooks throughtout different files.
&block - code to execute after ORM is intialized
93 94 95 |
# File 'lib/doozer/initializer.rb', line 93 def self.after_orm(&block) @@after_orm.push(block) if block_given? end |
.before_rackup(&block) ⇒ Object
Primary hook for adding/overriding Doozer::ViewHelpers methods. Code block is pushed onto an array which allows for multiple hooks throughtout different files.
&block - code to execute prior to Doozer.App.new being intialized.
100 101 102 |
# File 'lib/doozer/initializer.rb', line 100 def self.before_rackup(&block) @@before_rackup.push(block) if block_given? end |
.boot(env, app_path = nil) ⇒ Object
env - :development, :deployment, or :test app_path - optional path which overrides where the application is loaded from. Defaults to the Dir.pwd of script loading this file
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/doozer/initializer.rb', line 20 def self.boot(env, app_path=nil) #--load configs require 'doozer/configs' Doozer::Configs.set_app_path(app_path) Doozer::Configs.load(env) #--load orm Doozer::Initializer.orm #--load environment hooks Doozer::Initializer.environment #--call the after_orm_init features Doozer::Initializer.after_orm_init #--load the after orm gems Doozer.init_after_orm_gems #--load the after orm plugins Doozer.init_after_orm_plugins #--load app require 'doozer/app' #--call the before_rackup_init features Doozer::Initializer.before_rackup_init end |
.console(env, app_path = nil) ⇒ Object
TODO: test this again
85 86 87 88 |
# File 'lib/doozer/initializer.rb', line 85 def self.console(env, app_path=nil) self.boot(env, app_path=app_path) app = Doozer::App.new(args={}) end |
.environment ⇒ Object
Requires the root/config/environment.rb hooks.
This is where you can place your code to initialize additional plugins for models, extend ruby, or whatever else your app requires.
Example environment.rb
Time::DATE_FORMATS = “%B %Y”
Doozer::Initializer.after_orm do | config |
p "Extending some ORM, yo!"
end
Doozer::Initializer.before_rackup do | config |
p "Before rackup, horray for rackup!"
end
76 77 78 79 80 81 82 |
# File 'lib/doozer/initializer.rb', line 76 def self.environment begin require "#{Doozer::Configs.app_path}/config/environment" rescue => e Doozer::Configs.logger.error(e) end end |
.orm ⇒ Object
Checks to see if an ORM gem (active_record, data_mapper, or sequel) is specified in database.yml and loads it.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/doozer/initializer.rb', line 49 def self.orm begin # load orm layer (if required) if not Doozer::Configs.orm.nil? and not Doozer::Configs.db.nil? require "doozer/orm/#{Doozer::Configs.orm}" Doozer::ORM.load Doozer::Configs.orm_loaded = true end rescue => e Doozer::Configs.logger.error(e) end end |