Class: BunBo

Inherits:
Object
  • Object
show all
Defined in:
lib/bun_bo.rb,
lib/bun_bo/version.rb,
lib/bun_bo/results/success.rb,
lib/bun_bo/content_generator.rb,
lib/bun_bo/results/base_error.rb,
lib/bun_bo/results/file_existed.rb,
lib/bun_bo/results/file_not_found.rb,
lib/bun_bo/results/directory_result.rb

Defined Under Namespace

Classes: BaseError, ContentGenerator, DirectoryResult, FileExisted, FileNotFound, Success

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#run(input_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bun_bo.rb', line 10

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
    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?
      FileUtils.mkdir_p(test_folder)
      generator = ContentGenerator.new(Pathname.pwd)
      test_path.write(generator.generate)
      Success.new(test_path)
    else
      FileExisted.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