class Testifier::FileMaker

Public Class Methods

new(path) click to toggle source
# File lib/testifier/file_maker.rb, line 6
def initialize(path)
  @initial_path =  path
end

Public Instance Methods

basename() click to toggle source
# File lib/testifier/file_maker.rb, line 26
def basename
  File.basename(@initial_path, File.extname(@initial_path))
end
class_definition() click to toggle source
# File lib/testifier/file_maker.rb, line 51
    def class_definition
      <<-CLASS
class #{class_name}
end
CLASS
    end
class_file() click to toggle source
# File lib/testifier/file_maker.rb, line 18
def class_file
  "lib/#{dirname}#{basename}.rb"
end
create_class_file() click to toggle source
# File lib/testifier/file_maker.rb, line 37
def create_class_file
  unless File.exist?(class_file)
    puts "creating #{class_file}"
    File.open(class_file, "w") { |file| file.puts class_definition }
  end
end
create_files() click to toggle source
# File lib/testifier/file_maker.rb, line 30
def create_files
  make_dir_if_necessary(target_dir)
  make_dir_if_necessary(test_dir)
  create_class_file
  create_test_file
end
create_test_file() click to toggle source
# File lib/testifier/file_maker.rb, line 44
def create_test_file
  unless File.exist?(test_file)
    puts "creating #{test_file}"
    File.open(test_file, "w") { |file| file.puts test_definition }
  end
end
target_dir() click to toggle source
# File lib/testifier/file_maker.rb, line 10
def target_dir
  "lib/#{dirname}"
end
test_definition() click to toggle source
# File lib/testifier/file_maker.rb, line 58
    def test_definition
      <<-TEST
require "#{dirname}#{basename}"

describe #{class_name} do
end
TEST
    end
test_dir() click to toggle source
# File lib/testifier/file_maker.rb, line 14
def test_dir
  "spec/lib/#{dirname}"
end
test_file() click to toggle source
# File lib/testifier/file_maker.rb, line 22
def test_file
  "spec/lib/#{dirname}#{basename}_spec.rb"
end

Private Instance Methods

class_name() click to toggle source
# File lib/testifier/file_maker.rb, line 69
def class_name
  basename.camelize
end
dirname() click to toggle source
# File lib/testifier/file_maker.rb, line 79
def dirname
  dir = "#{File.dirname(@initial_path)}/"
  dir == "./" ? "" : dir
end
make_dir_if_necessary(filename) click to toggle source
# File lib/testifier/file_maker.rb, line 73
def make_dir_if_necessary(filename)
  unless File.exist?(filename)
    FileUtils.mkdir_p(filename)
  end
end