Module: EXEL::Job

Defined in:
lib/exel/job.rb

Overview

The Job module provides the main interface for defining and running EXEL jobs

Defined Under Namespace

Classes: Parser

Class Method Summary collapse

Class Method Details

.define(job_name, &block) ⇒ Object

Registers a new job

Parameters:

  • job_name (Symbol)

    A symbol to set as the name of this job. Used to run it later.

  • block

    A block of code that calls the EXEL DSL methods



10
11
12
13
# File 'lib/exel/job.rb', line 10

def define(job_name, &block)
  raise "Job #{job_name.inspect} is already defined" unless registry[job_name].nil?
  registry[job_name] = block
end

.registryHash

Returns A hash of all the defined jobs.

Returns:

  • (Hash)

    A hash of all the defined jobs



16
17
18
# File 'lib/exel/job.rb', line 16

def registry
  @registry ||= {}
end

.run(dsl_code_or_name, context = {}) ⇒ Object

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.

Parameters:

  • dsl_code_or_name (String, Symbol)

    As a symbol, the name of a registered job. As a string, the EXEL code to be run.

  • context (Context, Hash) (defaults to: {})

    (Optional) The initial Context to be passed to the job.

Raises:

  • If no job has been registered with the given name



27
28
29
30
# File 'lib/exel/job.rb', line 27

def run(dsl_code_or_name, context = {})
  context = EXEL::Context.new(context) if context.instance_of?(Hash)
  (ast = parse(dsl_code_or_name)) ? ast.start(context) : raise(%(Job "#{dsl_code_or_name}" not found))
end