module RubyValve::Core

Attributes

exception[R]
executed[R]
executed_steps[R]

Public Instance Methods

execute() click to toggle source
# File lib/ruby_valve/core.rb, line 11
def execute
  init

  if respond_to?(:after_exception)
    begin
      execute_methods
    rescue => e
      @exception = e
      send(:after_exception)
    end
  else
    execute_methods
  end

end
init() click to toggle source
# File lib/ruby_valve/core.rb, line 7
def init
  @skip_list = []
end
response() click to toggle source
# File lib/ruby_valve/core.rb, line 27
def response
  @response
end

Protected Instance Methods

abort(message, options = {}) click to toggle source
# File lib/ruby_valve/core.rb, line 89
def abort(message, options = {})
  @abort_triggered = true
  @abort_message = message 
  raise(RubyValve::AbortError, @abort_message) if options[:raise]
end
abort_triggered?() click to toggle source
# File lib/ruby_valve/core.rb, line 108
def abort_triggered?
  @abort_triggered
end
execute_methods() click to toggle source
# File lib/ruby_valve/core.rb, line 33
def execute_methods
  # begin
  @response = {}
  
  if respond_to?(:before_all)
    send(:before_all) 
    log_execution(:before_all)
  end

  execution_order.each do |_method|
    if !self.skip?(_method)
    
      if respond_to?(:before_each)
        send(:before_each)    
        log_execution(:before_each)           
      end

      #create method to store step results
      self.class.class_eval {attr_accessor :"#{_method}_result"}
      result = send(_method)

      #assign step result information
      @response[:"#{_method}_result"] = result
      send(:"#{_method}_result=", result) 

      #log step exec
      log_step_execution(_method)

      if respond_to?(:after_each)    
        send(:after_each)        
        log_execution(:after_each)
      end
    end
  end

  if respond_to?(:after_success) && !abort_triggered?
    send(:after_success) 
    log_execution(:after_success)
  end

  if respond_to?(:after_abort) && abort_triggered?
    send(:after_abort)  
    log_execution(:after_abort)
  end        
end
execution_order() click to toggle source
# File lib/ruby_valve/core.rb, line 118
def execution_order
  step_methods = methods.select {|meth| meth.to_s.match(/^step_[0-9]*$/)}

  step_methods.sort do |x,y|
    ordinal_x = x.to_s.split("_").last.to_i
    ordinal_y = y.to_s.split("_").last.to_i

    ordinal_x <=> ordinal_y
  end
end
log_execution(_method) click to toggle source
# File lib/ruby_valve/core.rb, line 85
def log_execution(_method)
  (@executed ||= []) << _method
end
log_step_execution(_method) click to toggle source

> logging methods

# File lib/ruby_valve/core.rb, line 80
def log_step_execution(_method)
  (@executed_steps ||= []) << _method
  log_execution(_method)
end
skip(*step_names) click to toggle source
# File lib/ruby_valve/core.rb, line 100
def skip(*step_names)
  skip_list.push *step_names
end
skip?(method_name) click to toggle source
# File lib/ruby_valve/core.rb, line 112
def skip?(method_name)
  return true if skip_all_steps?

  skip_list.include?(method_name)
end
skip_all_steps?() click to toggle source

> skip methods

# File lib/ruby_valve/core.rb, line 96
def skip_all_steps?
  abort_triggered?
end
skip_list() click to toggle source
# File lib/ruby_valve/core.rb, line 104
def skip_list
  @skip_list
end