Sha256: 8ebe6699b28d2b671bca30f3ba46c9b75db198a6a224328148093e155a635c42

Contents?: true

Size: 608 Bytes

Versions: 7

Compression:

Stored size: 608 Bytes

Contents

# require "eitil_core/files/create_file"

Kernel.module_eval do

  def create_file(file_name, data, directory: nil, suffix: nil, file_type: nil, append: false)
    
    directory = directory || "#{Dir.home}/data"
    suffix    = suffix    || DateTime.now.prettify
    file_type = file_type || "json"

    if file_type = "json"
      data = JSON.pretty_generate(data)
    end

    path = "#{directory}/#{file_name}_#{suffix}.#{file_type}"

    if append and Dir[path].present?
      File.open(path, "a+") { |f| f << data }
      return path
    end

    File.write(path, data)
    return path
    
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eitil-1.1.13 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.12 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.11 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.10 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.9 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.8 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.7 eitil_core/lib/eitil_core/files/create_file.rb