Sha256: 7232fa74bd48b27b7d0d3e600c3d42a114d697d89e150e5cec687122837ae08c

Contents?: true

Size: 671 Bytes

Versions: 7

Compression:

Stored size: 671 Bytes

Contents

require "tmpdir"
require "fileutils"

# This class encapsulates the pattern of creating a temporary configuration file
# from a String, easiliy referencing the directory to initialise a BBConfig and
# dispose of
#
class TmpConfig

  # Creates a temporary directory and a "config" file within using the contents
  # of a passed String.
  #
  # Recommended to use {#close} to delete
  #
  # @param [String] contents
  #
  def initialize(contents)
    @dir = Dir.mktmpdir
    @file = File.open(File.join(@dir, "config"), "w+")
    @file.write(contents)
    @file.close
    self
  end

  def path
    @dir
  end

  def close
    FileUtils.remove_entry_secure(@dir)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
brightbox-cli-1.2.2 spec/support/tmp_config.rb
brightbox-cli-1.2.1 spec/support/tmp_config.rb
brightbox-cli-1.2.0 spec/support/tmp_config.rb
brightbox-cli-1.1.0 spec/support/tmp_config.rb
brightbox-cli-1.0.0 spec/support/tmp_config.rb
brightbox-cli-1.0.0.rc2 spec/support/tmp_config.rb
brightbox-cli-1.0.0.rc1 spec/support/tmp_config.rb