# encoding: utf-8 require 'rubygems' require 'monitor' require 'bundler/setup' require_relative 'options' module Cuboid lib = Options.paths.lib require lib + 'support/mixins/spec_instances' require lib + 'system' require lib + 'version' require lib + 'support' require lib + 'ruby' require lib + 'error' require lib + 'utilities' require lib + 'snapshot' require lib + 'report' require lib + 'processes' require lib + 'application/runtime' # @author Tasos "Zapotek" Laskos class Application include Singleton module PrependMethods def run if !self.class.valid_options?( options ) fail ArgumentError, 'Invalid options!' end prepare return if aborted? || suspended? state.status = :running super if defined? super return if aborted? || suspended? clean_up state.status = :done true end # Cleans up the framework; should be called after running the audit or # after canceling a running scan. def clean_up return if @cleaned_up @cleaned_up = true state.resume state.status = :cleanup @finish_datetime = Time.now @start_datetime ||= Time.now state.running = false super if defined? super true end private # @note Must be called before calling any audit methods. # # Prepares the framework for the audit. # # * Sets the status to `:preparing`. # * Starts the clock. def prepare state.status = :preparing state.running = true @start_datetime = Time.now super if defined? super end end class < class Error < Cuboid::Error end def initialize super @runtime = Runtime.new end def runtime @runtime end def options=( opts ) Options.application = opts end def options Options.application end # @return [Hash] # # Framework statistics: # # * `:runtime` -- Scan runtime in seconds. def statistics { runtime: @start_datetime ? (@finish_datetime || Time.now) - @start_datetime : 0, } end def inspect stats = statistics s = "#<#{self.class} (#{status}) " s << "runtime=#{stats[:runtime]} " s << '>' end # @return [String] # Returns the version of the framework. def version Cuboid::VERSION end def self._spec_instance_cleanup( i ) # i.clean_up i.reset end def unsafe self end def application Cuboid::Application.application end def serializer self.class.serializer end def safe( &block ) raise ArgumentError, 'Missing block.' if !block_given? begin block.call self ensure clean_up reset end nil end end end