Gradual automation in Ruby

Gradual automation in Ruby

It’s the simplest piece of Ruby code you’ll read today. Also known as: do-nothing scripting. Original inspiration.


You want to codify a manual process like setting up another instance of your e-commerce app. It may involve several steps with varying potential for automation (like seed the db, set up a subdomain, set up admin account).

  • Solution 1 📖: lay out all steps in a wiki page and teach people to conform.
  • Solution 2 🧠: don’t even document the steps, keep it in your own head. Have people always come to you or discover it from scratch, develop tribal knowledge.
  • Solution 3 🖲: make everything happen at the push of a button in your glossy dashboard app. Spend weeks implementing it and months maintaining it. Lie to yourself that this is good ROI.
  • Solution 4 ⚙️: skip the UI part, write a script that automates it all. Wonder why people don’t use it.
  • Solution 5 📝 + ⚙️: make a do-nothing script that only tells you what to do next. Gradually automate it where it makes sense.

Advantages of a do-nothing script

  • It’s version controlled just as the rest of your stuff.
  • It’s easy to start with — at the beginning nothing needs to be automated.
  • It can keep track of your progress
  • You can automate some steps, leave the rest to be done manually

An example

The original example is in Python. This is how I once did it in Ruby. I hereby announce another name for this technique: Puts-Driven Automation.

  -> {
    puts "Create a user"
    puts "u = User.create!("
    puts "  name: '#{name}',"
    puts "  email: '#{email}',"
    puts "  company: '#{company}',"
    puts ")"
  -> {
    puts "Setup an account on a 3rd party service"

def ask_to_continue
  puts 'Continue? [Y/n]'
  input = STDIN.gets.chomp
  unless input == '' || /^[Yy]$/.match(input)
    puts 'User cancelled.'

STEPS.each_with_index do |step, i|
  puts "-----------------------------------------------------------------------"
  puts "Step #{i}"
  puts "-----------------------------------------------------------------------"
  ask_to_continue if i < (STEPS.size - 1)

I bet you can make the above snippet better!

Send me a gist showing how you do it and I’ll link your example here. DMs open.

Got comments? Reply under this tweet.

Source: Arkency

Leave a Reply

Your email address will not be published.