Module: ProtoProcessor::Strategy

Defined in:
lib/proto_processor/strategy.rb

Instance Method Summary collapse

Instance Method Details

#current_inputObject



32
33
34
# File 'lib/proto_processor/strategy.rb', line 32

def current_input
  @current_input ||= ''
end

#processObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/proto_processor/strategy.rb', line 24

def process
  raise NotImplementedError, "You must implement #process in your strategies"
end

#reportObject



3
4
5
# File 'lib/proto_processor/strategy.rb', line 3

def report
  @report ||= ProtoProcessor::Report.new
end

#run {|report| ... } ⇒ Object

Yields:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/proto_processor/strategy.rb', line 11

def run
  begin
    ProtoProcessor.logger.info "Running strategy #{self.class.name}"
    process
  rescue StandardError => e
    report.fail!(e)
    ProtoProcessor.logger.error e.class.name
    ProtoProcessor.logger.debug e.message + "\n" + e.backtrace.join("\n")
  end
  yield report if block_given?
  report
end

#run_task(task_class, options = nil, &block) ⇒ Object

Run a task and update input and report (but don’t update options)

If passed and array of options, run task for each option hash



39
40
41
42
# File 'lib/proto_processor/strategy.rb', line 39

def run_task(task_class, options = nil, &block)
  return false if options.nil?
  run_task_chain([*task_class], options, &block)
end

#runnerObject



7
8
9
# File 'lib/proto_processor/strategy.rb', line 7

def runner
  @task_runner ||= ProtoProcessor::TaskRunner.new(report)
end

#with_input(input) ⇒ Object



28
29
30
# File 'lib/proto_processor/strategy.rb', line 28

def with_input(input)
  @current_input = input#.dup # dup so we don't overwrite passed input later on
end