module TestProf

def activate(env_var, val = nil)

Contains workaround for applications using Spring.
equal to the provided value (if any).
Run block only if provided env var is present and
def activate(env_var, val = nil)
  if defined?(::Spring::Application)
    ::Spring.after_fork { activate!(env_var, val) { yield } }
  else
    activate!(env_var, val) { yield }
  end
end

def activate!(env_var, val)

def activate!(env_var, val)
  yield if ENV[env_var] && (val.nil? || ENV[env_var] == val)
end

def artifact_path(filename)

Return a path to store artifact
def artifact_path(filename)
  create_artifact_dir
  with_timestamps(
    ::File.join(
      config.output_dir,
      filename
    )
  )
end

def asset_path(filename)

Return absolute path to asset
def asset_path(filename)
  ::File.expand_path(filename, ::File.join(::File.dirname(__FILE__), "..", "assets"))
end

def config

def config
  @config ||= Configuration.new
end

def configure

def configure
  yield config
end

def create_artifact_dir

def create_artifact_dir
  FileUtils.mkdir_p(config.output_dir)[0]
end

def require(gem_name, msg = nil)

message if it fails to load
Require gem and shows a custom
def require(gem_name, msg = nil)
  Kernel.require gem_name
  block_given? ? yield : true
rescue LoadError
  log(:error, msg) if msg
  false
end

def with_timestamps(path)

def with_timestamps(path)
  return path unless config.timestamps?
  timestamps = "-#{now.to_i}"
  "#{path.sub(/\.\w+$/, '')}#{timestamps}#{::File.extname(path)}"
end