class Faker::File

Public Class Methods

dir(legacy_segment_count = NOT_GIVEN, legacy_root = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, segment_count: 3, root: nil, directory_separator: ::File::Separator) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/faker/default/file.rb, line 7
def dir(legacy_segment_count = NOT_GIVEN, legacy_root = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, segment_count: 3, root: nil, directory_separator: ::File::Separator)
  # rubocop:enable Metrics/ParameterLists
  warn_for_deprecated_arguments do |keywords|
    keywords << :segment_count if legacy_segment_count != NOT_GIVEN
    keywords << :root if legacy_root != NOT_GIVEN
    keywords << :directory_separator if legacy_directory_separator != NOT_GIVEN
  end

  Array
    .new(segment_count) { Faker::Internet.slug }
    .unshift(root)
    .compact
    .join(directory_separator)
    .squeeze(directory_separator)
end
extension() click to toggle source
# File lib/faker/default/file.rb, line 23
def extension
  fetch('file.extension')
end
file_name(legacy_dir = NOT_GIVEN, legacy_name = NOT_GIVEN, legacy_ext = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/faker/default/file.rb, line 32
def file_name(legacy_dir = NOT_GIVEN, legacy_name = NOT_GIVEN, legacy_ext = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator)
  # rubocop:enable Metrics/ParameterLists
  warn_for_deprecated_arguments do |keywords|
    keywords << :dir if legacy_dir != NOT_GIVEN
    keywords << :name if legacy_name != NOT_GIVEN
    keywords << :ext if legacy_ext != NOT_GIVEN
    keywords << :directory_separator if legacy_directory_separator != NOT_GIVEN
  end

  dir ||= dir(segment_count: 1)
  name ||= Faker::Lorem.word.downcase
  ext ||= extension

  [dir, name].join(directory_separator) + ".#{ext}"
end
mime_type() click to toggle source
# File lib/faker/default/file.rb, line 27
def mime_type
  fetch('file.mime_type')
end