Sha256: fceaa5670ec393e4f7c8f4ee1c9f9b34be8fef416a2a3aad335c2409334fe060

Contents?: true

Size: 609 Bytes

Versions: 55

Compression:

Stored size: 609 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

55 entries across 55 versions & 1 rubygems

Version Path
eitil-2.0.8 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.7 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.6 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.5 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.4 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.3 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.2 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.1 eitil_core/lib/eitil_core/files/create_file.rb
eitil-2.0.0 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.4.1 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.4.0 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.12 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.11 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.10 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.9 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.8 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.7 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.6 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.5 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.4 eitil_core/lib/eitil_core/files/create_file.rb