Skip to content

Instantly share code, notes, and snippets.

@revans
Created September 14, 2009 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revans/186781 to your computer and use it in GitHub Desktop.
Save revans/186781 to your computer and use it in GitHub Desktop.
version control api for web frameworks
# VersionControl.rb
#
# This is version control agnostic. You can use git,
# mercurial, subversion, bazaar
class VersionControl
class << self
# Run a command with any version control
#
# ==== Examples
#
# hg :init
# hg :init, :add, :commit => "-m 'First commit'"
# git :init, :add => '.', :commit => "-m 'First commit'"
# svn :add => "twofile.rb", :commit => "-m 'First Subversion commit'"
#
def method_missing(method, *args, &block)
begin
run(method.to_sym, *args)
rescue
super
end
end
private
# Run
#
# ==== Description
#
# Runs the command, with the command arguments.
# Supports single arguments like git :init, as well
# as multiple arguments like hg :init, :add, :commit => "-m 'first commit'"
#
def run(type, *args)
args.each do |command|
if command.is_a?(Symbol)
puts "#{type.to_s} #{command}"
else
command.each { |command, options| puts "#{type.to_s} #{command} #{options}" }
end
end
end
end
end
# Examples
VersionControl.hg :init
VersionControl.hg :init, :add, :commit => "-m 'First Mercurial commit'"
VersionControl.git :init
VersionControl.git :init, :add => '.', :commit => "-m 'First Git commit'"
VersionControl.svn :add => "twofile.rb", :commit => "-m 'First Subversion commit'"
VersionControl.bzr :init
VersionControl.bzr :init, :add, :commit => "-m 'First Bazaar commit'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment