Class: Rucola::Initializer
Overview
Rails-like Initializer responsible for processing configuration.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
The Configuration instance used by this Initializer instance.
Class Method Summary collapse
-
.boot ⇒ Object
Load the config/boot.rb file.
-
.do_boot ⇒ Object
Override this method from your Plugin.before_boot method if you need to alter behaviour before any of the application’s files are required and the app is started.
- .instance ⇒ Object
-
.load_plugins ⇒ Object
Loads all the plugins that are found in
plugins_root
. -
.plugins_root ⇒ Object
Returns the path to the plugins root directory.
-
.run ⇒ Object
Run the initializer and start the application.
-
.start_app ⇒ Object
Starts the application’s run loop.
Instance Method Summary collapse
-
#initialize ⇒ Initializer
constructor
Create an initializer instance.
- #load_application_initializers ⇒ Object
-
#process ⇒ Object
Step through the initialization routines.
-
#require_dependencies ⇒ Object
Requires all the dependencies specified in config/dependencies.rb.
-
#require_frameworks ⇒ Object
Requires all frameworks specified by the Configuration#objc_frameworks list.
-
#require_lib_source_files ⇒ Object
Requires any ruby source files in the app/lib/ directory.
-
#require_ruby_source_files ⇒ Object
Loops through the subdirectories of the app/ directory.
-
#require_ruby_source_files_in_dir_recursive(dir) ⇒ Object
Recursively requires any ruby source file that it finds.
-
#set_load_path! ⇒ Object
Set the paths from which your application will automatically load source files.
-
#use_reloader! ⇒ Object
Loads the
Reloader
lib ifuse_reloader
is set totrue
on theConfiguration
.
Constructor Details
#initialize ⇒ Initializer
Create an initializer instance.
126 127 128 |
# File 'lib/rucola/initializer.rb', line 126 def initialize @configuration = Configuration.new end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
The Configuration instance used by this Initializer instance.
123 124 125 |
# File 'lib/rucola/initializer.rb', line 123 def configuration @configuration end |
Class Method Details
.boot ⇒ Object
Load the config/boot.rb file.
66 67 68 69 70 |
# File 'lib/rucola/initializer.rb', line 66 def boot Rucola::Plugin.before_boot do_boot Rucola::Plugin.after_boot end |
.do_boot ⇒ Object
Override this method from your Plugin.before_boot method if you need to alter behaviour before any of the application’s files are required and the app is started.
75 76 77 |
# File 'lib/rucola/initializer.rb', line 75 def do_boot Kernel.require Rucola::RCApp.root_path + '/config/boot' end |
.instance ⇒ Object
61 62 63 |
# File 'lib/rucola/initializer.rb', line 61 def instance @initializer ||= new end |
.load_plugins ⇒ Object
Loads all the plugins that are found in plugins_root
.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rucola/initializer.rb', line 85 def load_plugins root = plugins_root if root.exist? root.children.each do |plugin| init_rb = plugin + 'init.rb' next unless init_rb.exist? Kernel.require init_rb end end end |
.plugins_root ⇒ Object
Returns the path to the plugins root directory. Eg /MyApp/vendor/plugins.
80 81 82 |
# File 'lib/rucola/initializer.rb', line 80 def plugins_root RUBYCOCOA_ROOT + 'vendor/plugins' end |
.run ⇒ Object
Run the initializer and start the application. Pass it a block to set the configuration.
Rucola::Initializer.run do |config|
config.use_debugger = true
# See +Configuration+ for more info on the options.
end
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rucola/initializer.rb', line 103 def run if @initializer.nil? @initializer = new yield @initializer.configuration if block_given? @initializer.process start_app else yield @initializer.configuration if block_given? end end |
Instance Method Details
#load_application_initializers ⇒ Object
199 200 201 202 203 |
# File 'lib/rucola/initializer.rb', line 199 def load_application_initializers Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer| load(initializer) end end |
#process ⇒ Object
Step through the initialization routines.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rucola/initializer.rb', line 131 def process Rucola::Plugin.before_process(self) # load the environment config @configuration.load_environment_configuration! Rucola::Debugger.use! if @configuration.use_debugger use_reloader! if @configuration.use_reloader require_dependencies require_frameworks require_lib_source_files require_ruby_source_files Rucola::Plugin.after_process(self) end |
#require_dependencies ⇒ Object
Requires all the dependencies specified in config/dependencies.rb
149 150 151 152 |
# File 'lib/rucola/initializer.rb', line 149 def require_dependencies deps_file = (RUBYCOCOA_ROOT + 'config/dependencies.rb').to_s Rucola::Dependencies.load(deps_file).require! end |
#require_frameworks ⇒ Object
Requires all frameworks specified by the Configuration#objc_frameworks list. This is also responsible for including osx/active_record_proxy if use_active_record? is true
157 158 159 |
# File 'lib/rucola/initializer.rb', line 157 def require_frameworks configuration.objc_frameworks.each { |framework| OSX.require_framework(framework) } end |
#require_lib_source_files ⇒ Object
Requires any ruby source files in the app/lib/ directory.
173 174 175 176 177 |
# File 'lib/rucola/initializer.rb', line 173 def require_lib_source_files Dir[RUBYCOCOA_ROOT + 'lib/*.rb'].each do |f| require f end end |
#require_ruby_source_files ⇒ Object
Loops through the subdirectories of the app/ directory. It requires any ruby file in any of the subdirectories and registers the required file in the hash @require_ruby_source_files with the name of the subdirectory as it’s key.
require_ruby_source_files # => :views=>[], :controllers=>
185 186 187 188 189 |
# File 'lib/rucola/initializer.rb', line 185 def require_ruby_source_files Dir[RUBYCOCOA_ROOT + 'app/**/*.rb'].each do |f| require f end end |
#require_ruby_source_files_in_dir_recursive(dir) ⇒ Object
Recursively requires any ruby source file that it finds.
162 163 164 165 166 167 168 169 170 |
# File 'lib/rucola/initializer.rb', line 162 def require_ruby_source_files_in_dir_recursive(dir) dir.children.each do |child| if child.directory? require_ruby_source_files_in_dir_recursive(child) next end require child if child.basename.to_s =~ /\.rb$/ end end |
#set_load_path! ⇒ Object
Set the paths from which your application will automatically load source files.
206 207 208 209 210 |
# File 'lib/rucola/initializer.rb', line 206 def set_load_path! load_paths = configuration.load_paths || [] # TODO: from script/console the configuration isn't ran. load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) } unless Rucola::RCApp.test? # FIXME: why?? $LOAD_PATH.uniq! end |