The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby Project Tree

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jay Fields

Posts: 765
Nickname: jayfields
Registered: Sep, 2006

Jay Fields is a software developer for ThoughtWorks
Ruby Project Tree Posted: Oct 5, 2006 7:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jay Fields.
Original Post: Ruby Project Tree
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jay Fields
Latest Posts From Jay Fields Thoughts

Advertisement
I was recently asked: How would you structure a (non-Rails) Ruby project?

Here's a list of the things I generally do when creating a new project:
  • Create lib and test folders to house the code and tests respectively.
  • Create a rakefile.rb with a task for running all the tests:
    task :default => :test

    task :test do
    require File.dirname(__FILE__) + '/test/all_tests.rb'
    end
  • Create a test file that runs all tests (all_tests.rb):
    Dir['**/*_test.rb'].each { |test_case| require test_case }
  • Create a test_helper file that handles common require calls:
    require 'test/unit'
    require 'mocha'
    require 'stubba'
    require File.dirname(__FILE__) + '/../lib/[project name]'
  • Create a file with the same name as my project in the lib folder. This file contains all the requires necessary to run the application/use the library:
    [example: sqldsl.rb]

    lib = File.dirname(__FILE__)

    require lib + '/object.rb'
    require lib + '/symbol.rb'
    require lib + '/array.rb'
    require lib + '/string.rb'
    require lib + '/numeric.rb'
    require lib + '/time.rb'
    require lib + '/sql_statement.rb'
    require lib + '/where_builder.rb'
    require lib + '/select.rb'
    require lib + '/insert.rb'
    require lib + '/update.rb'
    require lib + '/delete.rb'
I find this structure makes my life easier.

Of course, if you want this automated, you could always just use tree_surgeon.rb
require 'fileutils'

project_name = ARGV[0]
lib = project_name + "/lib"
test = project_name + "/test"
rakefile = project_name + '/rakefile.rb'
all_tests = test + "/all_tests.rb"
main = project_name + "/lib/" + project_name + ".rb"
test_helper = test + "/test_helper.rb"

FileUtils.rm_rf project_name

puts "creating: " + project_name
Dir.mkdir project_name

puts "creating: " + lib
Dir.mkdir lib

puts "creating: " + test
Dir.mkdir test

puts "creating: " + rakefile
File.open(rakefile, 'w') do |file|
file << <<-eos
task :default => :test

task :test do
require File.dirname(__FILE__) + '/test/all_tests.rb'
end
eos
end

puts "creating: " + all_tests
File.open(all_tests, 'w') do |file|
file << "Dir['**/*_test.rb'].each { |test_case| require test_case }"
end

puts "creating: " + main
FileUtils.touch main

puts "creating: " + test_helper
File.open(test_helper, 'w') do |file|
file << <<-eos
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/#{project_name}'
eos
end
Also, if you are creating a RubyGem it is recommended that you create README, TODO, and CHANGES files. Additionally, if your gem uses executables it is suggested that you store the executables in a bin folder and create a install.rb file that calls your executables.

Do you have other suggestions?

Read: Ruby Project Tree

Topic: Two More Eye-Opening Programming Language Experiences Previous Topic   Next Topic Topic: Camping is Still Your 4k Pinkyframework!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use