Created
September 14, 2009 17:22
-
-
Save revans/186781 to your computer and use it in GitHub Desktop.
version control api for web frameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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