Introducing Projectr

Mon, 02 May 2011 10:39:18 +0000

Why might you want to know the names of all the files in your project? One might turn the question around and ask why would you possibly would not want to, but maybe that’s not a constructive dialogue. So let’s list some use cases

As far as I can see from my survey of the Ruby world, the current practices for each of these use cases are pretty ad hoc. Maybe you write a file full of require or require_relative statements (as the RBP blog author likes to do), maybe you use a glob, maybe you write a MANIFEST file, but there seems to be a significant lack of DRYness about it all. This led me to think there is a gap in the market for

  1. a language for describing the files that a project comprises
  2. some tools to interrogate a project description written in this form and find out what’s in it
  3. some code to load them into a running interpreter – and for bonus points, when files have previously been loaded into said image but since changed on disk, to reload them. This could be used in irb sessions, or could form the basis of a development-oriented web server that reloads changed files without needing to be stopped and started all the time

Note that item 3 above gives us something that “file containing list of require statements” doesn’t, because it allows us to reload files that we’ve already seen instead of just saying “meh, seen it already”. If you’re using a comparatively low-powered machine then reloading your entire app in irb every time you change a method definition is unnecessarily and obviously slow. If you’re also using Bundler (which I rather like now i’s settled down a bit, and will write more about in a future entry) then the additional bundle exec is not just slow, it’s SLow with a capital S and a capital L and a pulsating ever-growing O that rules from the centre of the underworld.

Here’s one I made earlier

Projectr::Project.new :test do
  # directories may be named by symbols or strings
  directory :example do
    #as may files
    file "file1"
    file :file2
    directory "subdir" do 
      file :subdir_file
    end
  end
end

h=Projectr::Project[:test]
h.load!   # it loads all the files
# and again
h.load!   # nothing happens this time
# touch example/file1.rb
h.load!   # loads only the changed file

At the time of writing this, the github version does about that much, but is quite clearly still version 0. Stuff I am still thinking about:

I will doubtless form my own opinions on all of these issues in time and with more experience of using this tool in practice, but feedback on them and on the general approach is warmly welcomed.

Fork, clone, spindle, mutilate