Class: Praxis::Bootloader
- Inherits:
-
Object
- Object
- Praxis::Bootloader
- Defined in:
- lib/praxis/bootloader.rb
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#stages ⇒ Object
readonly
Returns the value of attribute stages.
Instance Method Summary collapse
- #after(*stage_path, &block) ⇒ Object
- #before(*stage_path, &block) ⇒ Object
- #config ⇒ Object
- #delete_stage(stage_name) ⇒ Object
-
#initialize(application) ⇒ Bootloader
constructor
A new instance of Bootloader.
- #root ⇒ Object
- #run ⇒ Object
- #setup! ⇒ Object
- #setup_stages! ⇒ Object
- #use(plugin, **options, &block) ⇒ Object
Constructor Details
#initialize(application) ⇒ Bootloader
Returns a new instance of Bootloader.
8 9 10 11 12 13 |
# File 'lib/praxis/bootloader.rb', line 8 def initialize(application) @application = application @stages = Array.new setup_stages! end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
5 6 7 |
# File 'lib/praxis/bootloader.rb', line 5 def application @application end |
#stages ⇒ Object (readonly)
Returns the value of attribute stages.
6 7 8 |
# File 'lib/praxis/bootloader.rb', line 6 def stages @stages end |
Instance Method Details
#after(*stage_path, &block) ⇒ Object
72 73 74 75 |
# File 'lib/praxis/bootloader.rb', line 72 def after(*stage_path, &block) stage_name = stage_path.shift stages.find { |stage| stage.name == stage_name }.after(*stage_path, &block) end |
#before(*stage_path, &block) ⇒ Object
67 68 69 70 |
# File 'lib/praxis/bootloader.rb', line 67 def before(*stage_path, &block) stage_name = stage_path.shift stages.find { |stage| stage.name == stage_name }.before(*stage_path, &block) end |
#config ⇒ Object
15 16 17 |
# File 'lib/praxis/bootloader.rb', line 15 def config @application.config end |
#delete_stage(stage_name) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/praxis/bootloader.rb', line 56 def delete_stage(stage_name) if (stage = stages.find { |stage| stage.name == stage_name }) stages.delete(stage) else raise Exceptions::StageNotFound.new( "Cannot remove stage with name #{stage_name}, stage does not exist." ) end end |
#root ⇒ Object
19 20 21 |
# File 'lib/praxis/bootloader.rb', line 19 def root @application.root end |
#run ⇒ Object
115 116 117 118 119 120 |
# File 'lib/praxis/bootloader.rb', line 115 def run stages.each do |stage| stage.setup! stage.run end end |
#setup! ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/praxis/bootloader.rb', line 107 def setup! # use the Stats and Notifications plugins by default use Praxis::Stats use Praxis::Notifications run end |
#setup_stages! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/praxis/bootloader.rb', line 23 def setup_stages! # Require environment first. they define constants and environment specific settings stages << BootloaderStages::Environment.new(:environment, application) # then setup plugins stages << BootloaderStages::PluginLoader.new(:plugins, application) # then the initializers. as it is their job to ensure monkey patches and other # config is in place first. stages << BootloaderStages::FileLoader.new(:initializers, application) # then require lib/ code. stages << BootloaderStages::FileLoader.new(:lib, application) # design-specific code. stages << BootloaderStages::SubgroupLoader.new(:design, application) # app-specific code. stages << BootloaderStages::SubgroupLoader.new(:app, application) # setup routing stages << BootloaderStages::Routing.new(:routing, application) # naggy warning about unloaded files stages << BootloaderStages::WarnUnloadedFiles.new(:warn_unloaded_files, application) after(:app) do Praxis::Mapper.finalize! Praxis::Blueprint.finalize! end end |
#use(plugin, **options, &block) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/praxis/bootloader.rb', line 77 def use(plugin,**, &block) if plugin.ancestors.include?(PluginConcern) plugin.setup! plugin = plugin::Plugin end instance = if plugin.ancestors.include?(Singleton) plugin.instance elsif plugin.kind_of?(Class) plugin.new else plugin end instance.application = application instance..merge!() instance.block = block if block_given? if application.plugins.key?(instance.config_key) raise "Can not use plugin: #{plugin}, another plugin is already registered with key: #{instance.config_key}" end if instance.config_key.nil? raise "Error initializing plugin: #{plugin}, config_key may not be nil." end application.plugins[instance.config_key] = instance instance end |