-
-
Save arunagw/5669597 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "rake" | |
require "rake/tasklib" | |
require "colored" | |
require "fileutils" | |
#require 'mysql' | |
#require 'jdbc-mysql' | |
class Object | |
def blank? | |
respond_to?(:empty?) ? empty? : !self | |
end | |
# An object is present if it's not blank. | |
def present? | |
!blank? | |
end | |
def presence | |
self if present? | |
end | |
end | |
class NilClass #:nodoc: | |
def blank? | |
true | |
end | |
end | |
class FalseClass #:nodoc: | |
def blank? | |
true | |
end | |
end | |
class TrueClass #:nodoc: | |
def blank? | |
false | |
end | |
end | |
class Array #:nodoc: | |
alias_method :blank?, :empty? | |
end | |
class Hash #:nodoc: | |
alias_method :blank?, :empty? | |
end | |
class String #:nodoc: | |
def blank? | |
self !~ /\S/ | |
end | |
end | |
class Numeric #:nodoc: | |
def blank? | |
false | |
end | |
end | |
include FileUtils | |
Rake.application.init("sake") | |
desc "Push current branch" | |
task :gp do | |
branch_name = @git_help.current_branch | |
puts "Pushing branch #{branch_name}" | |
system("git push origin #{branch_name} -u -v") | |
end | |
desc "Rebase current branch" | |
task :gb do | |
branch_name = @git_help.current_branch | |
puts "Rebasing branch #{branch_name}" | |
system("git rebase origin/#{branch_name}") | |
end | |
desc "Open merge tool with vimdiff" | |
task :gmt do | |
system("git mergetool -t vimdiff") | |
end | |
desc "Merge remote of current with current branch" | |
task :gm do | |
branch_name = @git_help.current_branch | |
puts "Merging origin/#{branch_name} with #{branch_name}" | |
system("git merge origin/#{branch_name}") | |
end | |
desc "Rebase remote of current with current branch" | |
task :gb do | |
branch_name = @git_help.current_branch | |
puts "Rebasing origin/#{branch_name} with #{branch_name}" | |
system("git rebase origin/#{branch_name}") | |
end | |
desc "Show diff" | |
task :gd do | |
system("git diff") | |
end | |
desc "Do hard reset" | |
task :grst do | |
system("git reset --hard HEAD") | |
end | |
desc "Creating a tracking local branch" | |
task :gct do | |
branch_name = ENV['branch'] | |
if(branch_name.blank?) | |
abort("Argument branch=".red+"<branch_name>".green) | |
else | |
system("git checkout --track -b #{branch_name} origin/#{branch_name}") | |
end | |
end | |
desc "Globally available task list" | |
task :default do | |
Rake.application.tasks.each do |task| | |
puts sprintf("%-25s : %s", task.name.bold.red, task.comment.blue) | |
end | |
end | |
desc "truncate db" | |
task :dbt do | |
db = ENV['db'] | |
username = ENV['user'] || 'root' | |
password = ENV['password'] || '' | |
host = ENV['host'] || 'localhost' | |
if not db.blank? | |
db_util = Sake::Database.new() | |
db_util.truncate_db(db,username,password,host) | |
else | |
abort("Please supply db name to truncate") | |
end | |
end | |
module Sake | |
class Git | |
def current_branch | |
cmd_output = `git symbolic-ref HEAD` | |
branch_name = cmd_output.strip.split("/")[-1] | |
branch_name | |
end | |
end | |
class Database | |
def truncate_db(db,username = 'root',password = '', host = 'localhost') | |
puts "Truncating Database : ".bold + db.red.bold | |
puts "** Press enter to continue **".green.bold | |
STDIN.getc | |
connection = Mysql.connect(host,username,password,db) | |
result = connection.real_query("show tables") | |
tables = [] | |
result.each_hash { |table| tables << table.values.first } | |
tables.each do |table| | |
puts "Truncating #{table}" | |
connection.real_query("truncate #{table}") | |
end | |
connection.close() | |
end | |
end | |
end | |
@git_help = Sake::Git.new() | |
Rake.application.top_level() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment