Sha256: 903991d5c7534ed42c485873f05594238e8e95728a34f7f79a4029e85dd7a354

Contents?: true

Size: 988 Bytes

Versions: 14

Compression:

Stored size: 988 Bytes

Contents

module Lucid
  module Formatter
    module Io
      def ensure_io(path_or_io, name)
        return nil if path_or_io.nil?
        return path_or_io if path_or_io.respond_to?(:write)
        file = File.open(path_or_io, Lucid.file_mode('w'))
        at_exit do
          unless file.closed?
            file.flush
            file.close
          end
        end
        file
      end

      def ensure_file(path, name)
        raise "You *must* specify --out FILE for the #{name} formatter" unless String === path
        raise "I can't write #{name} to a directory - it has to be a file" if File.directory?(path)
        ensure_io(path, name)
      end

      def ensure_dir(path, name)
        raise "You *must* specify --out DIR for the #{name} formatter" unless String === path
        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)
        path
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lucid-0.5.1 lib/lucid/formatter/io.rb
lucid-0.4.1 lib/lucid/formatter/io.rb
lucid-0.4.0 lib/lucid/formatter/io.rb
lucid-0.3.3 lib/lucid/formatter/io.rb
lucid-0.3.0 lib/lucid/formatter/io.rb
lucid-0.2.1 lib/lucid/formatter/io.rb
lucid-0.2.0 lib/lucid/formatter/io.rb
lucid-0.1.1 lib/lucid/formatter/io.rb
lucid-0.1.0 lib/lucid/formatter/io.rb
lucid-0.0.9 lib/lucid/formatter/io.rb
lucid-0.0.8 lib/lucid/formatter/io.rb
lucid-0.0.7 lib/lucid/formatter/io.rb
lucid-0.0.6 lib/lucid/formatter/io.rb
lucid-0.0.5 lib/lucid/formatter/io.rb