Class: Praxis::Bootloader

Inherits:
Object
  • Object
show all
Defined in:
lib/praxis/bootloader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#applicationObject (readonly)

Returns the value of attribute application.



6
7
8
# File 'lib/praxis/bootloader.rb', line 6

def application
  @application
end

#stagesObject (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



69
70
71
72
# File 'lib/praxis/bootloader.rb', line 69

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



64
65
66
67
# File 'lib/praxis/bootloader.rb', line 64

def before(*stage_path, &block)
  stage_name = stage_path.shift
  stages.find { |stage| stage.name == stage_name }.before(*stage_path, &block)
end

#configObject



15
16
17
# File 'lib/praxis/bootloader.rb', line 15

def config
  @application.config
end

#delete_stage(stage_name) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/praxis/bootloader.rb', line 53

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

#rootObject



19
20
21
# File 'lib/praxis/bootloader.rb', line 19

def root
  @application.root
end

#runObject



82
83
84
85
86
# File 'lib/praxis/bootloader.rb', line 82

def run
  stages.each do |stage|
    stage.run
  end
end

#setup!Object



78
79
80
# File 'lib/praxis/bootloader.rb', line 78

def setup!
  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
# 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 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, &block) ⇒ Object



74
75
76
# File 'lib/praxis/bootloader.rb', line 74

def use(plugin,&block)
  application.plugins << plugin.new(application, &block)
end