Auto

Automate everything!

Notice

This gem is currently under development. Some of what you see below is a fantasy.

Install


sudo gem install auto --source http://gemcutter.org

Introduction

Auto is a framework for writing automation scripts and plugins for those scripts.


require 'rubygems'
require 'auto'

question :name => "What is your name?"
question :delete => "Delete file when finished? (y/n)"

file "#{@name}.txt" do |f|
  f << 'Append to text file'
  f = 'Overwrite text file'
end

file("#{@name}.txt").delete if @delete

Save it and run it like you would any other Ruby script.

In this example, question and file are both methods provided by the plugins auto-question and auto-file, respectively. They are included when you install the auto gem, but other plugins can be obtained via Rubygems.

Tasks

Auto has a tasks system similar to Capistrano or Rake. In the previous example, if you had saved your script to ~/.auto/my/name.rb, you would be able to run it by executing auto my:name in Terminal.

Tasks may also be included via plugin. See the Authoring Plugins section for more information.

Sessions

Installing the auto gem also installs auto-session, which allows you to record the input to your Auto scripts and replay them later.

To save a session, run your script or task with the SESSION environment variable:


SESSION=name ruby my_name.rb
SESSION=name auto my:name

This session would be saved in ~/.auto/session/name.rb (run it by executing auto session:name). It might look like this:


answer :name => 'Joe'
answer :delete => false
run 'my:name'

The session script is executed as any other Auto script. This is cool because you can modify your session files to get custom input for certain questions.


question :name => "What is your last name?"
answer :delete => false
run 'my:name'

You also could have deleted the :name answer to ask that question upon running the session.

Authoring Plugins

Plugins have a lib directory just like any other gem. Here is how the lib file for the Foo plugin might look:


# lib/auto/foo.rb
module Auto
  module Foo

    def foo(*args)
      Foo.instance args
    end

    class Foo
      class <<self
      
        def instance(args)
          # Do something
        end
      end
    end
  end
end

Auto uses the gem name (auto-foo) to find lib/auto/foo.rb and include Auto::Foo into the environment. Now you can call the foo method in any of your Auto scripts.

Auto plugins must have gem names with auto- as a prefix to be automatically required.

Include Auto tasks with your plugin by adding a .auto directory to your gem, just as you do with your home directory (~/.auto).