class Scintilla::Runner
Public Class Methods
run()
click to toggle source
# File lib/scintilla/runner.rb, line 5 def self.run scripts.each(&:run) end
script_name(full_file_path, without_extension = false)
click to toggle source
Extract script_name
from file_name, removing timestamp and optionally removing extension.
@param [<String>] full_file_path the full file path, e.g. /a/b/c.rb @param [<Boolean>] without_extension remove extension from file name.
Defaults to false
@return [<String>] the script name, e.g. c.rb
# File lib/scintilla/runner.rb, line 52 def self.script_name(full_file_path, without_extension = false) name = File.basename(full_file_path).gsub(/^\d+_/, '') # remove timestamp name = name.gsub(/\.rb$/, '') if without_extension name end
scripts(conditional_require = true)
click to toggle source
Get the list of scripts to be ran.
@param [<Boolean>] conditional_require whether to only require
scripts that still haven't ran. Defaults to true.
@return [<Array<Scintilla::Runnable>>] the list of Runnable
objects
to be ran.
# File lib/scintilla/runner.rb, line 17 def self.scripts(conditional_require = true) scripts = require_scripts(conditional_require) scripts.sort.inject([]) do |scripts_to_run, filename| klass = script_name(filename, true).camelize.constantize scripts_to_run << klass.new end end
Private Class Methods
require_scripts(conditional_require)
click to toggle source
Requires the scripts in the db/scintilla path, to allow loading them for execution.
@param [<Boolean>] conditional_require whether to only require
scripts that still haven't ran. This is useful if older scripts contain references to no longer present classes, and to boost performances. Set it to false for debugging purposes.
# File lib/scintilla/runner.rb, line 34 def self.require_scripts(conditional_require) scripts = Dir[Rails.root.join('db', 'scintilla', '*.rb')] if conditional_require scripts.reject! { |f| ScintillaScript.exists?(filename: script_name(f, false)) } end scripts.each { |f| require f } end