module Cucumber::Formatter::Io

Public Class Methods

included(formatter_class) click to toggle source
# File lib/cucumber/formatter/io.rb, line 51
def self.included(formatter_class)
  formatter_class.extend(ClassMethods)
end

Public Instance Methods

ensure_dir(path, name) click to toggle source
# File lib/cucumber/formatter/io.rb, line 70
def ensure_dir(path, name)
  raise "You *must* specify --out DIR for the #{name} formatter" unless String == path.class
  raise "I can't write #{name} reports to a file - it has to be a directory" if File.file?(path)
  FileUtils.mkdir_p(path) unless File.directory?(path)
  File.absolute_path path
end
ensure_file(path, name) click to toggle source
# File lib/cucumber/formatter/io.rb, line 63
def ensure_file(path, name)
  raise "You *must* specify --out FILE for the #{name} formatter" unless String == path.class
  raise "I can't write #{name} to a directory - it has to be a file" if File.directory?(path)
  raise "I can't write #{name} to a file in the non-existing directory #{File.dirname(path)}" unless File.directory?(File.dirname(path))
  ensure_io(path, nil)
end
ensure_io(path_or_url_or_io, error_stream) click to toggle source
# File lib/cucumber/formatter/io.rb, line 12
def ensure_io(path_or_url_or_io, error_stream)
  return nil if path_or_url_or_io.nil?
  return path_or_url_or_io if io?(path_or_url_or_io)

  io = if url?(path_or_url_or_io)
         url = path_or_url_or_io
         reporter = url.start_with?(Cucumber::Cli::Options::CUCUMBER_PUBLISH_URL) ? URLReporter.new(error_stream) : NoReporter.new
         HTTPIO.open(url, nil, reporter)
       else
         File.open(path_or_url_or_io, Cucumber.file_mode('w'))
       end
  @io_objects_to_close ||= []
  @io_objects_to_close.push(io)
  io
end
io?(path_or_url_or_io) click to toggle source
# File lib/cucumber/formatter/io.rb, line 55
def io?(path_or_url_or_io)
  path_or_url_or_io.respond_to?(:write)
end
url?(path_or_url_or_io) click to toggle source
# File lib/cucumber/formatter/io.rb, line 59
def url?(path_or_url_or_io)
  path_or_url_or_io.match(%r{^https?://})
end