Class: Vedeu::Runtime::Bootstrap

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/runtime/bootstrap.rb

Overview

Provides the mechanism to start up a generated application.

This class loads all necessary client application files and initializes Vedeu with this data, then starts the client application.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Vedeu::Runtime::Bootstrap

Returns a new instance of Vedeu::Runtime::Bootstrap.

Parameters:

  • argv (Array<String>)


23
24
25
# File 'lib/vedeu/runtime/bootstrap.rb', line 23

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvArray<String> (readonly, protected)

Returns:

  • (Array<String>)


44
45
46
# File 'lib/vedeu/runtime/bootstrap.rb', line 44

def argv
  @argv
end

Class Method Details

.start(argv = ARGV) ⇒ void

This method returns an undefined value.

Parameters:

  • argv (Array<String>) (defaults to: ARGV)


15
16
17
# File 'lib/vedeu/runtime/bootstrap.rb', line 15

def self.start(argv = ARGV)
  new(argv).start
end

Instance Method Details

#base_pathString (private)

Returns:

  • (String)


49
50
51
# File 'lib/vedeu/runtime/bootstrap.rb', line 49

def base_path
  Vedeu::Configuration.base_path
end

#client_application!void (private)

This method returns an undefined value.



66
67
68
69
70
71
72
73
74
75
# File 'lib/vedeu/runtime/bootstrap.rb', line 66

def client_application!
  [
    'app/views/templates/**/*'.freeze,
    'app/views/interfaces/**/*'.freeze,
    'app/controllers/**/*'.freeze,
    'app/helpers/**/*'.freeze,
    'app/views/**/*'.freeze,
    'app/models/keymaps/**/*'.freeze,
  ].each { |path| load(File.join(base_path, path)) }
end

#client_configuration!void (private)

Note:

config/configuration.rb is already loaded so don’t load it twice.

This method returns an undefined value.



57
58
59
60
61
62
63
# File 'lib/vedeu/runtime/bootstrap.rb', line 57

def client_configuration!
  Dir[File.join(base_path, 'config/**/*')].each do |path|
    next if path =~ %r{config/configuration\.rb}

    load(path)
  end
end

#client_initialize!void (private)

This method returns an undefined value.



78
79
80
81
82
83
84
85
86
# File 'lib/vedeu/runtime/bootstrap.rb', line 78

def client_initialize!
  if Vedeu::Configuration.root
    Vedeu.trigger(:_goto_, *Vedeu::Configuration.root)

  else
    Vedeu.log_stderr(type: :debug, message: client_initialize_error)

  end
end

#client_initialize_errorString (private)

Returns:

  • (String)


118
119
120
121
122
123
124
125
# File 'lib/vedeu/runtime/bootstrap.rb', line 118

def client_initialize_error
  "Please update the 'root' setting in " \
  "'config/configuration.rb' to start Vedeu using this " \
  "controller and action: (args are optional)\n\n" \
  "Vedeu.configure do\n" \
  "  root :some_controller, :show, *args\n" \
  "end\n\n".freeze
end

#configure_log!void (private)

This method returns an undefined value.



111
112
113
114
115
# File 'lib/vedeu/runtime/bootstrap.rb', line 111

def configure_log!
  Vedeu.configure do
    log('/tmp/vedeu_bootstrap.log')
  end unless Vedeu::Configuration.log?
end

#load(path) ⇒ String (private)

Load each of the loadable files.

Parameters:

  • path (String)

Returns:

  • (String)


92
93
94
95
96
# File 'lib/vedeu/runtime/bootstrap.rb', line 92

def load(path)
  loadables(path).each { |file| Kernel.load(file) }

  path
end

#loadables(path) ⇒ Array<String> (private)

Collect each of the files from the client application directories by path excluding ‘.’ and ‘..’ and only loading files with the ‘.rb’ extension.

Parameters:

  • path (String)

Returns:

  • (Array<String>)


104
105
106
107
108
# File 'lib/vedeu/runtime/bootstrap.rb', line 104

def loadables(path)
  Dir.glob(path).select do |file|
    File.file?(file) && File.extname(file) == '.rb'.freeze
  end
end

#startvoid

This method returns an undefined value.

Loads all of the client application files so that Vedeu has access to them, then launches the client application.



31
32
33
34
35
36
37
38
# File 'lib/vedeu/runtime/bootstrap.rb', line 31

def start
  configure_log!
  client_configuration!
  client_application!
  client_initialize!

  Vedeu::Launcher.execute!(argv)
end