Module: OnlyofficeFileHelper::CreateMethods

Included in:
FileHelper
Defined in:
lib/onlyoffice_file_helper/create_methods.rb

Overview

Methods used to create something

Instance Method Summary collapse

Instance Method Details

#create_file_with_content(file_path: '/tmp/temp_file.ext', content: '') ⇒ String

Create file with content

Parameters:

  • file_path (String) (defaults to: '/tmp/temp_file.ext')

    path to created file

  • content (String) (defaults to: '')

    content of file

Returns:

  • (String)

    path to created file



19
20
21
22
23
# File 'lib/onlyoffice_file_helper/create_methods.rb', line 19

def create_file_with_content(file_path: '/tmp/temp_file.ext', content: '')
  File.write(file_path, content)
  OnlyofficeLoggerHelper.log("Created file: #{file_path} with content: #{content}")
  file_path
end

#create_file_with_size(file_path: '/tmp/temp_file.ext', size: '1G') ⇒ String

Create empty file with size

Parameters:

  • file_path (String) (defaults to: '/tmp/temp_file.ext')

    path to created file

  • size (String) (defaults to: '1G')

    file size, may use binary indexes lik ‘256M’, ‘15G’

Returns:

  • (String)

    path to created file



29
30
31
32
# File 'lib/onlyoffice_file_helper/create_methods.rb', line 29

def create_file_with_size(file_path: '/tmp/temp_file.ext', size: '1G')
  `fallocate -l #{size} #{file_path}`
  file_path
end

#create_folder(path) ⇒ Void

Gracefully create folder. Do not fail if already exists

Parameters:

  • path (String)

    path to folder

Returns:

  • (Void)


9
10
11
12
13
# File 'lib/onlyoffice_file_helper/create_methods.rb', line 9

def create_folder(path)
  FileUtils.mkdir_p(path) unless File.directory?(path)
rescue Errno::EEXIST
  true
end