Class: Raad::Service

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

Overview

The main execution class for Raad. This will execute in the at_exit handler to run the server.

Constant Summary collapse

CALLERS_TO_IGNORE =

Set of caller regex’s to be skippe when looking for our API file

[ # :nodoc:
  /\/raad(\/(service))?\.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.



20
21
22
# File 'lib/raad/service.rb', line 20

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.



26
27
28
29
30
# File 'lib/raad/service.rb', line 26

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)


44
45
46
47
48
49
50
# File 'lib/raad/service.rb', line 44

def self.run!
  file = File.basename(service_file, '.rb')
  service = Object.module_eval(camel_case(file)).new

  runner = Raad::Runner.new(ARGV, service)
  runner.run
end

.service_fileString

Find the service_file that was used to execute the service

Returns:

  • (String)

    The service file



35
36
37
38
39
# File 'lib/raad/service.rb', line 35

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