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.
-
.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(command = :process, configuration = Configuration.new) {|configuration| ... } ⇒ Object
Run the initializer and start the application.
-
.start_app ⇒ Object
Starts the application’s run loop.
Instance Method Summary collapse
-
#copy_load_paths_for_release ⇒ Object
Copy the default load paths to the resource directory for the application if we are building a release, otherwise we do nothing.
-
#initialize(configuration) ⇒ Initializer
constructor
Create an initializer instance that references the given Configuration instance.
- #load_application_initializers ⇒ Object
-
#load_environment ⇒ Object
Loads the environment specified by Configuration#environment_path, which can be debug or release.
-
#process ⇒ Object
Step through the initialization routines, skipping the active_record routines if active_record isnt’ being used.
-
#require_frameworks ⇒ Object
Requires all frameworks specified by the Configuration#objc_frameworks list.
-
#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.
-
#require_rucola_support ⇒ Object
Loads the Rucola support library.
-
#set_load_path ⇒ Object
Set the paths from which your application will automatically load source files.
Constructor Details
#initialize(configuration) ⇒ Initializer
Create an initializer instance that references the given Configuration instance.
107 108 109 |
# File 'lib/rucola/initializer.rb', line 107 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
The Configuration instance used by this Initializer instance.
53 54 55 |
# File 'lib/rucola/initializer.rb', line 53 def configuration @configuration end |
Class Method Details
.boot ⇒ Object
Load the config/boot.rb file.
57 58 59 60 61 |
# File 'lib/rucola/initializer.rb', line 57 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.
66 67 68 |
# File 'lib/rucola/initializer.rb', line 66 def do_boot require RUBYCOCOA_ROOT + 'config/boot' end |
.load_plugins ⇒ Object
Loads all the plugins that are found in plugins_root
.
76 77 78 79 80 81 82 83 84 |
# File 'lib/rucola/initializer.rb', line 76 def load_plugins root = plugins_root if root.exist? root.children.each do |plugin| next unless plugin.directory? Kernel.require plugin + 'init.rb' end end end |
.plugins_root ⇒ Object
Returns the path to the plugins root directory. Eg /MyApp/vendor/plugins.
71 72 73 |
# File 'lib/rucola/initializer.rb', line 71 def plugins_root RUBYCOCOA_ROOT + 'vendor/plugins' end |
.run(command = :process, configuration = Configuration.new) {|configuration| ... } ⇒ Object
Run the initializer and start the application. The #process method is run by default which runs all the initialization routines. You can alternatively specify a command to run.
OSX::Initializer.run(:set_load_path)
92 93 94 95 96 97 |
# File 'lib/rucola/initializer.rb', line 92 def run(command = :process, configuration = Configuration.new) yield configuration if block_given? initializer = new configuration initializer.send(command) start_app end |
.start_app ⇒ Object
Starts the application’s run loop.
100 101 102 |
# File 'lib/rucola/initializer.rb', line 100 def start_app OSX.NSApplicationMain(0, nil) unless RUBYCOCOA_ENV == 'test' || ENV['DONT_START_RUBYCOCOA_APP'] end |
Instance Method Details
#copy_load_paths_for_release ⇒ Object
Copy the default load paths to the resource directory for the application if we are building a release, otherwise we do nothing. When in debug or test mode, the files are loaded directly from your working directory.
TODO: Remove debug database from released app if it exists.
195 196 197 198 199 200 |
# File 'lib/rucola/initializer.rb', line 195 def copy_load_paths_for_release return unless configuration.environment == 'release' configuration.load_paths.each do |path| `cp -R #{path} #{RUBYCOCOA_ROOT}/#{File.basename(path)}` if File.directory?(path) end end |
#load_application_initializers ⇒ Object
162 163 164 165 166 |
# File 'lib/rucola/initializer.rb', line 162 def load_application_initializers Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer| load(initializer) end end |
#load_environment ⇒ Object
Loads the environment specified by Configuration#environment_path, which can be debug or release
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/rucola/initializer.rb', line 170 def load_environment return if @environment_loaded @environment_loaded = true config = configuration constants = self.class.constants eval(IO.read(configuration.environment_path), binding, configuration.environment_path) (self.class.constants - constants).each do |const| Object.const_set(const, self.class.const_get(const)) end end |
#process ⇒ Object
Step through the initialization routines, skipping the active_record routines if active_record isnt’ being used.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/rucola/initializer.rb', line 113 def process Rucola::Plugin.before_process(self) unless ENV['DYLD_LIBRARY_PATH'].nil? set_load_path copy_load_paths_for_release end require_rucola_support require_frameworks require_ruby_source_files load_environment Rucola::Plugin.after_process(self) 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
130 131 132 |
# File 'lib/rucola/initializer.rb', line 130 def require_frameworks configuration.objc_frameworks.each { |framework| OSX.require_framework(framework) } 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=>
156 157 158 159 160 |
# File 'lib/rucola/initializer.rb', line 156 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.
140 141 142 143 144 145 146 147 148 |
# File 'lib/rucola/initializer.rb', line 140 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 |
#require_rucola_support ⇒ Object
Loads the Rucola support library
135 136 137 |
# File 'lib/rucola/initializer.rb', line 135 def require_rucola_support require Pathname.new(__FILE__).dirname + 'rucola_support' end |
#set_load_path ⇒ Object
Set the paths from which your application will automatically load source files.
184 185 186 187 188 |
# File 'lib/rucola/initializer.rb', line 184 def set_load_path load_paths = configuration.load_paths load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) } unless RUBYCOCOA_ENV == 'test' # FIXME: why?? $LOAD_PATH.uniq! end |