module EXEL::Job
The Job
module provides the main interface for defining and running EXEL
jobs
Public Class Methods
define(job_name, &block)
click to toggle source
Registers a new job
@param job_name [Symbol] A symbol to set as the name of this job. Used to run it later. @param block A block of code that calls the EXEL
DSL methods
# File lib/exel/job.rb, line 11 def define(job_name, &block) raise "Job #{job_name.inspect} is already defined" unless registry[job_name].nil? registry[job_name] = block end
registry()
click to toggle source
@return [Hash] A hash of all the defined jobs
# File lib/exel/job.rb, line 17 def registry @registry ||= {} end
run(dsl_code_or_name, context = {})
click to toggle source
If given a symbol as the first parameter, it attempts to run a previously registered job using that name. Alternatively, a string of code can be passed to be parsed and run directly.
@param dsl_code_or_name [String, Symbol] As a symbol, the name of a registered job. As a string, the EXEL
code
to be run.
@param context [Context, Hash] (Optional) The initial {Context} to be passed to the job. @raise If no job has been registered with the given name
# File lib/exel/job.rb, line 28 def run(dsl_code_or_name, context = {}) context = EXEL::Context.new(context) if context.instance_of?(Hash) ast = parse(dsl_code_or_name) ast ? ast.start(context) : raise(%(Job "#{dsl_code_or_name}" not found)) context end
Private Class Methods
parse(dsl_code_or_name)
click to toggle source
# File lib/exel/job.rb, line 37 def parse(dsl_code_or_name) if dsl_code_or_name.is_a?(Symbol) job = registry[dsl_code_or_name] Parser.parse(job) if job else Parser.parse(dsl_code_or_name) end end