Class: Apiwork::Export::Pipeline::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/export/pipeline/writer.rb

Class Method Summary collapse

Class Method Details

.clean(output:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apiwork/export/pipeline/writer.rb', line 22

def clean(output:)
  if File.exist?(output)
    if File.directory?(output)
      FileUtils.rm_rf(output)
      Rails.logger.debug "Cleaned directory: #{output}"
    else
      FileUtils.rm_f(output)
      Rails.logger.debug "Cleaned file: #{output}"
    end
  else
    Rails.logger.debug "Path does not exist: #{output}"
  end
end

.file_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/apiwork/export/pipeline/writer.rb', line 36

def file_path?(path)
  File.extname(path) != ''
end

.write(api_base_path: nil, content:, export_name: nil, extension:, output:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/apiwork/export/pipeline/writer.rb', line 11

def write(api_base_path: nil, content:, export_name: nil, extension:, output:)
  if file_path?(output)
    write_file(content, output)
  else
    raise ArgumentError, 'api_base_path and export_name required when output is a directory' if api_base_path.blank? || export_name.blank?

    file_path = build_file_path(output, api_base_path, export_name, extension)
    write_file(content, file_path)
  end
end