Class: Doozer::Initializer

Inherits:
Object show all
Defined in:
lib/doozer/initializer.rb

Overview

This is the main class which facilitates booting Doozer components and hooks.

Calling boot initializes Doozer in the following order:

  1. Doozer::Configs

  2. require ORM

  3. require app_path/config/environment.rb

  4. call Doozer::Initializer.after_orm_init

  5. call Doozer.init_after_orm_gems - initialized in app_path/gems/plugins/init.rb

  6. call Doozer.init_after_orm_plugins - initialized in app_path/gems/plugins/init.rb

  7. require Doozer::App

  8. call Doozer::Initializer.before_rackup_init

Constant Summary collapse

@@after_orm =
[]
@@before_rackup =
[]

Class Method Summary collapse

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

.environmentObject

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

.ormObject

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