thoughtbot-limerick_rake 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ Limerick Rake
2
+ =============
3
+
4
+ A collection of useful rake tasks.
5
+
6
+ h2. Database
7
+
8
+ Read tasks/database.rake for details for configuration.
9
+
10
+ * rake db:bootstrap:load - Load initial database fixtures (in db/bootstrap/*.yml) into the current environment's database. Load specific fixtures using FIXTURES=x,y
11
+ * rake db:indexes:missing - Prints a list of unindexed foreign keys so you can index them.
12
+ * rake db:shell - Launches the database shell using the values defined in config/database.yml.
13
+ * rake db:validate_models - Run model validations on all model records in database.
14
+
15
+ h2. Git
16
+
17
+ * rake git:push:staging - Merge a branch into the origin/staging branch.
18
+ * rake git:push:production - Merge the staging branch into origin/production for launch.
19
+ * rake git:diff:staging - Show the difference between current branch and origin/staging.
20
+ * rake git:diff:production - Show the difference between origin/staging and origin/production.
21
+ * rake git:pull:suspenders - Pull updates from suspenders, the thoughtbot rails template.
22
+ * rake git:branch:production - Branch origin/production into BRANCH locally.
23
+
24
+ h2. Backup
25
+
26
+ * rake backup:db - Backup the current database. Timestamped file is created as :rails_root/../db-name-timestamp.sql
27
+ * rake backup:assets - Backup all assets under public/system. File is created as :rails_root/../system.tgz
28
+
29
+ h2. Haml & Sass
30
+
31
+ * rake sass:all_css2sass - Convert all CSS files in public/stylesheets to Sass.
32
+ * rake sass:all_sass2css - Convert all Sass files to CSS.
33
+ * rake haml:all_html2haml - Convert all HTML files to Haml.
34
+
35
+ h2. Subversion
36
+
37
+ * rake svn:add - Adds all files with an svn status flag of '?'
38
+ * rake svn:delete - Deletes all files with an svn status flag of '!'
39
+ * rake svn:log - Writes the log file to doc/svn_log.txt
40
+ * rake svn:update\_svn\_ignore - Updates svn:ignore from .svnignore
41
+
42
+ The Limerick Rake
43
+ =================
44
+
45
+ Traditional Irish song. "YouTube":http://www.youtube.com/v/e8moLHIW8xw
46
+
47
+ I am a young fellow that's easy and bold,
48
+ In Castletown conners I'm very well known.
49
+ In Newcastle West I spent many a note,
50
+ With Kitty and Judy and Mary.
51
+
52
+ My father rebuked me for being such a rake,
53
+ And spending me time in such frolicsome ways,
54
+ But I ne'er could forget the good nature of Jane,
55
+ Agus fágaimíd siúd mar atá sé.
56
+
57
+ My parents had reared me to shake and to mow,
58
+ To plough and to harrow, to reap and to sow.
59
+ But my heart being airy to drop it so low,
60
+ I set out on high speculation.
61
+
62
+ On paper and parchment they taught me to write,
63
+ In Euclid and grammar they opened my eyes,
64
+ And in multiplication in truth I was bright,
65
+ Agus fágaimíd siúd mar atá sé.
66
+
67
+ If I chance for to go to the town of Rathkeale,
68
+ The girls all round me do flock on the square.
69
+ Some give me a bottle and others sweet cakes,
70
+ To treat me unknown to their parents.
71
+
72
+ There is one from Askeaton and one from the Pike,
73
+ Another from Arda, my heart was beguiled,
74
+ Tho' being from the mountains her stockings are white,
75
+ Agus fágaimíd siúd mar atá sé.
76
+
77
+ To quarrel for riches I ne'er was inclined,
78
+ For the greatest of misers that must leave all behind.
79
+ I'll purchase a cow that will never run dry,
80
+ And I'll milk her by twisting her horn.
81
+
82
+ John Damer of Shronel had plenty of gold,
83
+ And Lord Devonshire's treasures are twenty times more,
84
+ But he's laid on his back among nettles and stones,
85
+ Agus fágaimíd siúd mar atá sé.
86
+
87
+ The old cow could be milked without clover or grass,
88
+ She'd be pampered with corn, good barley and hops.
89
+ She's warm and stout, and she's free in the paps,
90
+ And she'll milk without spancil or halter.
91
+
92
+ The man that will drink it will cock his caubeen,
93
+ And if anyone laughs there'd be wigs on the green,
94
+ And the feeble old hag will get supple and free,
95
+ Agus fágaimíd siúd mar atá sé.
96
+
97
+ There's some say I'm foolish and more say I'm wise,
98
+ But being fond of the women I think is no crime,
99
+ For the son of King David had ten hundred wives,
100
+ And his wisdom was highly regarded.
101
+
102
+ I'll take a good garden and live at my ease,
103
+ And each woman and child can partake of the same,
104
+ If there'd be war in the cabin, themselves they'd be to blame,
105
+ Agus fágaimíd siúd mar atá sé.
106
+
107
+ And now for the future I mean to be wise,
108
+ And I'll send for the women that acted so kind,
109
+ I'd marry them all on the morrow by and by,
110
+ If the clergy agree to the bargain.
111
+
112
+ And when I'd be old and my soul is at peace,
113
+ These women will crowd for to cry at my wake,
114
+ And their sons and their daughters will offer their prayer,
115
+ To the Lord for the soul of their father.
116
+
117
+ License
118
+ -------
119
+
120
+ MIT License, under the same terms as Ruby.
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "limerick_rake"
3
+ s.version = "0.0.1"
4
+ s.date = "2008-10-06"
5
+ s.summary = "A collection of useful rake tasks."
6
+ s.email = "support@thoughtbot.com"
7
+ s.homepage = "http://github.com/thoughtbot/limerick_rake"
8
+ s.description = "A collection of useful rake tasks."
9
+ s.authors = ["the Ruby community", "thoughtbot, inc."]
10
+ s.files = ["README.textile",
11
+ "limerick_rake.gemspec",
12
+ "tasks/backup.rake",
13
+ "tasks/db/bootstrap.rake",
14
+ "tasks/db/indexes.rake",
15
+ "tasks/db/shell.rake",
16
+ "tasks/db/validate_models.rake",
17
+ "tasks/git.rake",
18
+ "tasks/haml_sass.rake",
19
+ "tasks/svn.rake"]
20
+ end
@@ -0,0 +1,39 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ namespace :backup do
5
+ desc "Backup the current database. Timestamped file is created as :rails_root/../db-name-timestamp.sql"
6
+ task :db => :environment do
7
+ config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
8
+ filename = "#{config['database'].gsub(/_/, '-')}-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.sql"
9
+ backupdir = File.expand_path(File.join(RAILS_ROOT, '..'))
10
+ filepath = File.join(backupdir, filename)
11
+ mysqldump = `which mysqldump`.strip
12
+ options = "-e -u #{config['username']}"
13
+ options += " -p#{config['password']}" if config['password']
14
+ options += " -h #{config['host']}" if config['host']
15
+
16
+ raise RuntimeError, "I only work with mysql." unless config['adapter'] == 'mysql'
17
+ raise RuntimeError, "Cannot find mysqldump." if mysqldump.blank?
18
+
19
+ FileUtils.mkdir_p backupdir
20
+ `#{mysqldump} #{options} #{config['database']} > #{filepath}`
21
+ puts "#{config['database']} => #{filepath}"
22
+ end
23
+
24
+
25
+ desc "Backup all assets under public/system. File is created as :rails_root/../system.tgz"
26
+ task :assets do
27
+ path = (Pathname.new(RAILS_ROOT) + 'public' + 'system').realpath
28
+ base_dir = path.parent
29
+ system_dir = path.basename
30
+ outfile = (Pathname.new(RAILS_ROOT) + '..').realpath + 'system.tgz'
31
+
32
+ cd base_dir
33
+ `tar -czf #{outfile} #{system_dir}`
34
+ puts "Assets => #{outfile}"
35
+ end
36
+ end
37
+
38
+ desc 'Backup the database and all assets by running the backup:db and backup:assets tasks.'
39
+ task :backup => ["backup:db", "backup:assets"]
@@ -0,0 +1,15 @@
1
+ namespace :db do
2
+ desc "Loads a schema.rb file into the database and then loads the initial database fixtures."
3
+ task :bootstrap => ['db:schema:load', 'db:bootstrap:load']
4
+
5
+ namespace :bootstrap do
6
+ desc "Load initial database fixtures (in db/bootstrap/*.yml) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
7
+ task :load => :environment do
8
+ require 'active_record/fixtures'
9
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
10
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'db', 'bootstrap', '*.{yml,csv}'))).each do |fixture_file|
11
+ Fixtures.create_fixtures('db/bootstrap', File.basename(fixture_file, '.*'))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ namespace :db do
2
+ namespace :indexes do
3
+ desc "Prints a list of unindexed foreign keys so you can index them"
4
+ task :missing => :environment do
5
+ indexes = {}
6
+ conn = ActiveRecord::Base.connection
7
+ conn.tables.each do |table|
8
+ indexed_columns = conn.indexes(table).map { |i| i.columns }.flatten
9
+ conn.columns(table).each do |column|
10
+ if column.name.match(/_id/) && !indexed_columns.include?(column.name)
11
+ indexes[table] ||= []
12
+ indexes[table] << column.name
13
+ end
14
+ end
15
+ end
16
+ puts "Foreign Keys:"
17
+ indexes.each do |table, columns|
18
+ puts columns.map { |c| "\s\sadd_index '#{table}', '#{c}'\n"}
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ namespace :db do
2
+ desc 'Launches the database shell using the values defined in config/database.yml'
3
+ task :shell => :environment do
4
+ config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
5
+ command = ""
6
+
7
+ case config['adapter']
8
+ when 'mysql'
9
+ command << "mysql "
10
+ command << "--host=#{config['host'] || 'localhost'} "
11
+ command << "--port=#{config['port'] || 3306} "
12
+ command << "--user=#{config['username'] || 'root'} "
13
+ command << "--password=#{config['password'] || ''} "
14
+ command << config['database']
15
+ when 'postgresql'
16
+ puts 'You should consider switching to MySQL or get off your butt and submit a patch'
17
+ else
18
+ command << "echo Unsupported database adapter: #{config['adapter']}"
19
+ end
20
+
21
+ system command
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ namespace :db do
2
+ # From http://blog.hasmanythrough.com/2006/8/27/validate-all-your-records
3
+ desc "Run model validations on all model records in database"
4
+ task :validate_models => :environment do
5
+ # because rails loads stuff on demand...
6
+ Dir.glob(RAILS_ROOT + '/app/models/**/*.rb').each do |file|
7
+ silence_warnings do
8
+ require file
9
+ end
10
+ end
11
+
12
+ Object.subclasses_of(ActiveRecord::Base).select { |c| c.base_class == c}.sort_by(&:name).each do |klass|
13
+ next if klass.name == "CGI::Session::ActiveRecordStore::Session"
14
+ invalid_count = 0
15
+ total = klass.count
16
+ chunk_size = 1000
17
+ (total / chunk_size + 1).times do |i|
18
+ chunk = klass.find(:all, :offset => (i * chunk_size), :limit => chunk_size)
19
+ chunk.reject(&:valid?).each do |record|
20
+ invalid_count += 1
21
+ puts "#{klass} #{record.id}: #{record.errors.full_messages.to_sentence}"
22
+ end rescue nil
23
+ end
24
+ puts "#{invalid_count} of #{total} #{klass.name.pluralize} are invalid." if invalid_count > 0
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,129 @@
1
+ module GitCommands
2
+ class ShellError < RuntimeError; end
3
+
4
+ @logging = ENV['LOGGING'] != "false"
5
+
6
+ def self.run cmd, *expected_exitstatuses
7
+ puts "+ #{cmd}" if @logging
8
+ output = `#{cmd} 2>&1`
9
+ puts output.gsub(/^/, "- ") if @logging
10
+ expected_exitstatuses << 0 if expected_exitstatuses.empty?
11
+ raise ShellError.new("ERROR: '#{cmd}' failed with exit status #{$?.exitstatus}") unless
12
+ [expected_exitstatuses].flatten.include?( $?.exitstatus )
13
+ output
14
+ end
15
+
16
+ def self.current_branch
17
+ run("git branch --no-color | grep '*' | cut -d ' ' -f 2").chomp
18
+ end
19
+
20
+ def self.remote_branch_exists?(branch)
21
+ ! run("git branch -r --no-color | grep '#{branch}'").blank?
22
+ end
23
+
24
+ def self.ensure_clean_working_directory!
25
+ return if run("git status", 0, 1).match(/working directory clean/)
26
+ raise "Must have clean working directory"
27
+ end
28
+
29
+ def self.diff_staging
30
+ puts run("git diff HEAD origin/staging")
31
+ end
32
+
33
+ def self.diff_production
34
+ puts run("git diff origin/staging origin/production")
35
+ end
36
+
37
+ def self.push_staging(branch)
38
+ raise "Branch must not be blank" if branch.blank?
39
+ raise "origin/staging branch does not exist" unless remote_branch_exists?("origin/staging")
40
+ ensure_clean_working_directory!
41
+ begin
42
+ run "git fetch"
43
+ run "git branch -f staging origin/staging"
44
+ run "git checkout staging"
45
+ run "git pull . #{branch}"
46
+ run "git push origin staging"
47
+ rescue
48
+ puts "Creating staging tag failed."
49
+ raise
50
+ ensure
51
+ run "git checkout master"
52
+ run "git branch -D staging"
53
+ end
54
+ end
55
+
56
+ def self.push_production
57
+ raise "origin/production branch does not exist" unless remote_branch_exists?("origin/production")
58
+ ensure_clean_working_directory!
59
+ begin
60
+ run "git fetch"
61
+ run "git branch -f production origin/production"
62
+ run "git checkout production"
63
+ run "git pull origin staging"
64
+ run "git push origin production"
65
+ rescue
66
+ puts "Creating production tag failed."
67
+ raise
68
+ ensure
69
+ run "git checkout master"
70
+ run "git branch -D production"
71
+ end
72
+ end
73
+
74
+ def self.branch_production(branch)
75
+ raise "Branch must not be blank" if branch.blank?
76
+ ensure_clean_working_directory!
77
+ run "git branch -f #{branch} origin/production"
78
+ run "git checkout #{branch}"
79
+ end
80
+
81
+ def self.pull_template
82
+ ensure_clean_working_directory!
83
+ run "git pull git://github.com/thoughtbot/suspenders.git master"
84
+ end
85
+ end
86
+
87
+ namespace :git do
88
+ namespace :push do
89
+ desc "Merge a branch into the origin/staging branch."
90
+ task :staging do
91
+ branch = ENV['BRANCH'].blank? ? GitCommands.current_branch : ENV['BRANCH']
92
+ puts "Tagging #{branch} as origin/staging"
93
+ GitCommands.push_staging(branch)
94
+ end
95
+
96
+ desc "Merge the staging branch into origin/production for launch."
97
+ task :production do
98
+ GitCommands.push_production
99
+ end
100
+ end
101
+
102
+ namespace :diff do
103
+ desc "Show the difference between current branch and origin/staging."
104
+ task :staging do
105
+ GitCommands.diff_staging
106
+ end
107
+
108
+ desc "Show the difference between origin/staging and origin/production."
109
+ task :production do
110
+ GitCommands.diff_production
111
+ end
112
+ end
113
+
114
+ namespace :pull do
115
+ desc "Pull updates from suspenders, the thoughtbot rails template."
116
+ task :suspenders do
117
+ GitCommands.pull_template
118
+ end
119
+ end
120
+
121
+ namespace :branch do
122
+ desc "Branch origin/production into BRANCH locally."
123
+ task :production do
124
+ branch = ENV['BRANCH'].blank? ? GitCommands.current_branch : ENV['BRANCH']
125
+ puts "Branching origin/production into #{branch}"
126
+ GitCommands.branch_production(branch)
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,78 @@
1
+ # Dan Croak, February 2008
2
+
3
+ @css_dir = "#{RAILS_ROOT}/public/stylesheets"
4
+ @sass_dir = "#{@css_dir}/sass"
5
+ @views_dir = "#{RAILS_ROOT}/app/views"
6
+
7
+ def convert_css_to_sass(basename)
8
+ system "css2sass #{@css_dir}/#{basename}.css > #{@sass_dir}/#{basename}.sass"
9
+ end
10
+
11
+ def convert_sass_to_css(basename)
12
+ system "sass #{@sass_dir}/#{basename}.sass > #{@css_dir}/#{basename}.css"
13
+ end
14
+
15
+ def convert_html_to_haml(controller, basename)
16
+ extname = basename.include?("erb") ? ".html.erb" : ".rhtml"
17
+ basename = basename.split(".").first
18
+ system "html2haml #{@views_dir}/#{controller}/#{basename}#{extname} > #{@views_dir}/#{controller}/#{basename}.html.haml"
19
+ system "rm #{@views_dir}/#{controller}/#{basename}#{extname}"
20
+ end
21
+
22
+ namespace :sass do
23
+ desc "Convert all CSS files to Sass."
24
+ task :all_css2sass => :environment do
25
+ begin
26
+ Dir.mkdir(@sass_dir)
27
+ rescue Exception => e
28
+ nil
29
+ end
30
+
31
+ files = Dir.entries(@css_dir).find_all do |f|
32
+ File.extname("#{@css_dir}/#{f}") == ".css" &&
33
+ File.basename("#{@css_dir}/#{f}") !~ /^[.]/
34
+ end
35
+
36
+ files.each do |filename|
37
+ basename = File.basename("#{@css_dir}/#{filename}", ".css")
38
+ convert_css_to_sass basename
39
+ convert_sass_to_css basename
40
+ end
41
+ end
42
+
43
+ desc "Convert all Sass files to CSS."
44
+ task :all_sass2css => :environment do
45
+ files = Dir.entries(@sass_dir).find_all do |f|
46
+ File.extname("#{@sass_dir}/#{f}") == ".sass" &&
47
+ File.basename("#{@sass_dir}/#{f}") !~ /^[.]/
48
+ end
49
+
50
+ files.each do |filename|
51
+ basename = File.basename("#{@sass_dir}/#{filename}", ".sass")
52
+ convert_sass_to_css basename
53
+ end
54
+ end
55
+ end
56
+
57
+ namespace :haml do
58
+ desc "Convert all HTML files to Haml."
59
+ task :all_html2haml => :environment do
60
+ controllers = Dir.entries(@views_dir).find_all do |c|
61
+ File.directory?("#{@views_dir}/#{c}") &&
62
+ File.basename("#{@views_dir}/#{c}") !~ /^[.]/
63
+ end
64
+
65
+ controllers.each do |controller|
66
+ files = Dir.entries("#{@views_dir}/#{controller}").find_all do |f|
67
+ (File.new("#{@views_dir}/#{controller}/#{f}").path.include?(".html.erb") ||
68
+ File.new("#{@views_dir}/#{controller}/#{f}").path.include?(".rhtml")) &&
69
+ File.basename("#{@views_dir}/#{controller}/#{f}") !~ /^[.]/
70
+ end
71
+ files.each do |filename|
72
+ basename = File.basename("#{@views_dir}/#{controller}/#{filename}")
73
+ convert_html_to_haml controller, basename
74
+ end
75
+ end
76
+ end
77
+ end
78
+
@@ -0,0 +1,21 @@
1
+ # Pulled together from various mailing lists.
2
+
3
+ namespace :svn do
4
+ desc "Adds all files with an svn status flag of '?'"
5
+ task(:add) { system %q(svn status | awk '/\\?/ {print $2}' | xargs svn add) }
6
+
7
+ desc "Deletes all files with an svn status flag of '!'"
8
+ task(:delete) { system %q(svn status | awk '/\\!/ {print $2}' | xargs svn delete) }
9
+
10
+ desc "Writes the log file to doc/svn_log.txt"
11
+ task(:log) do
12
+ File.delete("#{RAILS_ROOT}/doc/svn_log.txt") if File::exists?("#{RAILS_ROOT}/doc/svn_log.txt")
13
+ File.new("#{RAILS_ROOT}/doc/svn_log.txt", "w+")
14
+ system("svn log >> doc/svn_log.txt")
15
+ end
16
+
17
+ desc 'Updates svn:ignore from .svnignore'
18
+ task(:update_svn_ignore) do
19
+ system %q(svn propset svn:ignore -F .svnignore .)
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thoughtbot-limerick_rake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - the Ruby community
8
+ - thoughtbot, inc.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-10-06 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: A collection of useful rake tasks.
18
+ email: support@thoughtbot.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - README.textile
27
+ - limerick_rake.gemspec
28
+ - tasks/backup.rake
29
+ - tasks/db/bootstrap.rake
30
+ - tasks/db/indexes.rake
31
+ - tasks/db/shell.rake
32
+ - tasks/db/validate_models.rake
33
+ - tasks/git.rake
34
+ - tasks/haml_sass.rake
35
+ - tasks/svn.rake
36
+ has_rdoc: false
37
+ homepage: http://github.com/thoughtbot/limerick_rake
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A collection of useful rake tasks.
62
+ test_files: []
63
+