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-1.3.3 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.2 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.1 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.3.0 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.2.4 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.2.3 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.2.2 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.2.1 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.2.0 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.39 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.38 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.37 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.36 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.35 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.34 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.33 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.32 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.31 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.30 eitil_core/lib/eitil_core/files/create_file.rb
eitil-1.1.29 eitil_core/lib/eitil_core/files/create_file.rb