Class: Raad::Bootstrap

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

Overview

The bootstrap class for Raad. This will execute in the at_exit handler to run the service.

Constant Summary collapse

CALLERS_TO_IGNORE =

:nodoc:

[ # :nodoc:
  /\/raad(\/(bootstrap))?\.rb$/,    # all raad code
  /rubygems\/custom_require\.rb$/,  # rubygems require hacks
  /bundler(\/runtime)?\.rb/,        # bundler require hacks
  /<internal:/                      # internal in ruby >= 1.9.2
]

Class Method Summary collapse

Class Method Details

.caller_filesObject

Like Kernel#caller but excluding certain magic entries and without line / method information; the resulting array contains filenames only.



18
19
20
# File 'lib/raad/bootstrap.rb', line 18

def self.caller_files
  caller_locations.map { |file, line| file }
end

.caller_locationsObject

like caller_files, but containing Arrays rather than strings with the first element being the file, and the second being the line.



24
25
26
27
28
# File 'lib/raad/bootstrap.rb', line 24

def self.caller_locations
  caller(1).
    map    { |line| line.split(/:(?=\d|in )/)[0,2] }.
    reject { |file, line| CALLERS_TO_IGNORE.any? { |pattern| file =~ pattern } }
end

.run!Nil

execute the service

Returns:

  • (Nil)


42
43
44
45
# File 'lib/raad/bootstrap.rb', line 42

def self.run!
  service_class = Object.module_eval(camel_case(File.basename(service_file, '.rb')))
  Runner.new(ARGV, service_class).run
end

.service_fileString

find the service_file that was used to execute the service

Returns:

  • (String)

    The service file



33
34
35
36
37
# File 'lib/raad/bootstrap.rb', line 33

def self.service_file
  c = caller_files.first
  c = $0 if !c || c.empty?
  c
end