0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A simple wrapper class for running adhoc scripts on sets of data.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

AdhocScript

So many times, mostly in Rails app, I find myself making a file like bin/adhoc/regen_user_avatar_jan_2013.rb that goes like this:

require File.expand_path( '../config/environment.rb', __FILE__ )

User.where( 'avatar_upload IS NOT NULL' ).find_each do |user|
  user.regenerate_avatar!
end

...or something along those lines. And then I want to know, well, how long will this take? How far through all these users am I?

What I don't want to do is implement this progress status stuff everytime myself. So now I can just use AdhocScript :)

Installation

Most likely you update your Gemfile and bundle install.

gem 'adhoc_script', require: false

Usage

The script above becomes:

require File.expand_path( '../config/environment.rb', __FILE__ )
require 'adhoc_script'

scope = User.where( 'avatar_upload IS NOT NULL' )
AdhocScript.new( 'Regenerating avatars', scope ).run do |user|
  user.regenerate_avatar!
end

...almost the same, really. But the output looks like this:

- Regenerating avatars: 50% (Remaining: 26 minutes)

...and then a little while later:

/ Regenerating avatars: 75% (Remaining: 13 minutes)

You can also use it with just about any object that responds to #count:

#!/usr/bin/env ruby
# A completely rediculous example!

require 'adhoc_script'

$total = 0
def add( n )
  $total += n
end

AdhocScript.new( 'Count to 10000', (1..100000), :each ).run(&method(:add))

puts "Total: #{$total}"

Contributing

Maybe we could use a few other formatters? A progress bar, etc?

  1. Clone git://github.com/rfunduk/adhoc_script.git
  2. Create local branch.
  3. Make changes.
  4. rake test and return to 3 until passing.
  5. Commit, push and open a pull request.