class BunBo

Constants

RUBY_EXTENSIONS
VERSION

Public Instance Methods

run(input_path) click to toggle source
# File lib/bun_bo.rb, line 13
def run(input_path)
  input_path = Pathname.new(input_path)

  if input_path.file?
    folder_path, file_name = input_path.split
    extension = file_name.extname

    if RUBY_EXTENSIONS.include?(extension)
      base_name = file_name.basename(extension)
      test_folder = folder_path.sub(/^(app|lib)/, 'spec')
      test_path = test_folder.join("#{base_name}_spec").sub_ext(".rb")

      if test_path.exist?
        FileExisted.new(test_path)
      else
        FileUtils.mkdir_p(test_folder)
        generator = ContentGenerator.new(Pathname.pwd)
        test_path.write(generator.generate)
        Success.new(test_path)
      end
    else
      WrongExtension.new(test_path)
    end
  elsif input_path.directory?
    result = input_path.each_child.map { |child| run(child) }
    BunBo::DirectoryResult.new(result)
  else
    FileNotFound.new
  end
end