Class: EXEL::Job::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/exel/job.rb

Overview

Defines the EXEL DSL methods and is used to convert a block of Ruby code into an abstract syntax tree (AST)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



49
50
51
# File 'lib/exel/job.rb', line 49

def initialize
  @ast = SequenceNode.new
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



47
48
49
# File 'lib/exel/job.rb', line 47

def ast
  @ast
end

Class Method Details

.parse(dsl_proc_or_code) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/exel/job.rb', line 53

def self.parse(dsl_proc_or_code)
  parser = Parser.new
  if dsl_proc_or_code.is_a?(::Proc)
    parser.instance_eval(&dsl_proc_or_code)
  else
    parser.instance_eval(dsl_proc_or_code)
  end
  parser.ast
end

Instance Method Details

#async(options = {}, &block) ⇒ Object



68
69
70
# File 'lib/exel/job.rb', line 68

def async(options = {}, &block)
  add_instruction_node(Processors::AsyncProcessor, parse(block), options)
end

#contextObject



85
86
87
# File 'lib/exel/job.rb', line 85

def context
  DeferredContextValue.new
end

#listen(options) ⇒ Object



80
81
82
83
# File 'lib/exel/job.rb', line 80

def listen(options)
  instruction = ListenInstruction.new(options.fetch(:for), options.fetch(:with))
  @ast.add_child(InstructionNode.new(instruction))
end

#process(options, &block) ⇒ Object



63
64
65
66
# File 'lib/exel/job.rb', line 63

def process(options, &block)
  processor_class = options.delete(:with)
  add_instruction_node(processor_class, parse(block), options)
end

#run(options = {}, &block) ⇒ Object



76
77
78
# File 'lib/exel/job.rb', line 76

def run(options = {}, &block)
  add_instruction_node(Processors::RunProcessor, parse(block), options)
end

#split(options = {}, &block) ⇒ Object



72
73
74
# File 'lib/exel/job.rb', line 72

def split(options = {}, &block)
  add_instruction_node(Processors::SplitProcessor, parse(block), options)
end