class EXEL::Job::Parser
Defines the EXEL
DSL methods and is used to convert a block of Ruby code into an abstract syntax tree (AST)
Attributes
ast[R]
Public Class Methods
new()
click to toggle source
# File lib/exel/job.rb, line 51 def initialize @ast = SequenceNode.new end
parse(dsl_proc_or_code)
click to toggle source
# File lib/exel/job.rb, line 55 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
Public Instance Methods
async(options = {}, &block)
click to toggle source
# File lib/exel/job.rb, line 70 def async(options = {}, &block) add_instruction_node(Processors::AsyncProcessor, parse(block), options) end
context()
click to toggle source
# File lib/exel/job.rb, line 87 def context DeferredContextValue.new end
listen(options)
click to toggle source
# File lib/exel/job.rb, line 82 def listen(options) instruction = ListenInstruction.new(options.fetch(:for), options.fetch(:with)) @ast.add_child(InstructionNode.new(instruction)) end
process(options, &block)
click to toggle source
# File lib/exel/job.rb, line 65 def process(options, &block) processor_class = options.delete(:with) add_instruction_node(processor_class, parse(block), options) end
run(options = {}, &block)
click to toggle source
# File lib/exel/job.rb, line 78 def run(options = {}, &block) add_instruction_node(Processors::RunProcessor, parse(block), options) end
split(options = {}, &block)
click to toggle source
# File lib/exel/job.rb, line 74 def split(options = {}, &block) add_instruction_node(Processors::SplitProcessor, parse(block), options) end
Private Instance Methods
add_instruction_node(processor, subtree, args = {})
click to toggle source
# File lib/exel/job.rb, line 97 def add_instruction_node(processor, subtree, args = {}) instruction = EXEL::Instruction.new(processor, args, subtree: subtree) node = subtree.nil? ? InstructionNode.new(instruction) : InstructionNode.new(instruction, children: [subtree]) @ast.add_child(node) end
parse(block)
click to toggle source
# File lib/exel/job.rb, line 93 def parse(block) block.nil? ? nil : Parser.parse(block) end