Class: Generator
- Inherits:
-
Object
- Object
- Generator
- Defined in:
- lib/why_test/generator.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
-
#create(framework_name) ⇒ Hash
Creates a hash with the relevant information for generating our testing files.
-
#initialize(framework) ⇒ Generator
constructor
A new instance of Generator.
-
#write_files(root_directory = '.') ⇒ Object
Write the files.
Constructor Details
#initialize(framework) ⇒ Generator
Returns a new instance of Generator.
5 6 7 |
# File 'lib/why_test/generator.rb', line 5 def initialize(framework) @details = create(framework) end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
3 4 5 |
# File 'lib/why_test/generator.rb', line 3 def directory @directory end |
Instance Method Details
#create(framework_name) ⇒ Hash
Creates a hash with the relevant information for generating our testing files.
to be created (:files), and the rakefile (:rakfile).
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/why_test/generator.rb', line 15 def create(framework_name) results = Hash[:framework => framework_name, :directories => [], :files => [], :rakefile => 'Rakefile'] dir = File.join(File.dirname(File.(__FILE__)), 'generators', framework_name) Dir.chdir dir Dir["**/*"].each do |f| results[:files].push f unless f == 'Rakefile' or File.directory? f results[:directories].push f if File.directory? f end results end |
#write_files(root_directory = '.') ⇒ Object
Write the files.
directory)
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/why_test/generator.rb', line 33 def write_files(root_directory='.') base_dir = File. root_directory @template_directory = File.join(File.dirname(__FILE__), 'generators', @details[:framework]) system "mkdir -p #{base_dir}" unless File.exists?(base_dir) Dir.chdir base_dir create_rakefile create_directories write_test_files end |