<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: rake code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 08:17:34 GMT</pubDate>
    <description>DZone Snippets: rake code</description>
    <item>
      <title>Rake task to set all S3 files public_read</title>
      <link>http://snippets.dzone.com/posts/show/5766</link>
      <description>//  If you ever need to make sure all your Amazon S3 files are set to public_read, here's a rake task&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;namespace :s3 do&lt;br /&gt;  desc "Make all objects in S3 public_read"&lt;br /&gt;  task :make_public_readable do&lt;br /&gt;    require 'aws/s3'&lt;br /&gt;    # you might have this setup as env vars, doesn't work for me as i have more than one AWS account&lt;br /&gt;    AWS::S3::Base.establish_connection!(:access_key_id =&gt; '',:secret_access_key =&gt; '')    &lt;br /&gt;    &lt;br /&gt;    marker = ""&lt;br /&gt;    &lt;br /&gt;    loop do&lt;br /&gt;      objects = AWS::S3::Bucket.objects('your_bucket', :marker=&gt;marker, :max_keys=&gt;100)&lt;br /&gt;      puts "found #{objects.size} objects"&lt;br /&gt;    &lt;br /&gt;      break if objects.size == 0&lt;br /&gt;    &lt;br /&gt;      marker = objects.last.key&lt;br /&gt;      puts "new marker is \"#{marker}\""&lt;br /&gt;    &lt;br /&gt;      public_grant = AWS::S3::ACL::Grant.grant :public_read&lt;br /&gt;  &lt;br /&gt;      objects.each do |o|&lt;br /&gt;        if not o.acl.grants.include? public_grant&lt;br /&gt;          puts "\"#{o.key}\" does not include public_read"&lt;br /&gt;          o.acl.grants &lt;&lt; public_grant&lt;br /&gt;          o.acl(o.acl)&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 15 Jul 2008 01:00:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5766</guid>
      <author>spiceee (Spiceee)</author>
    </item>
    <item>
      <title>rake task for restart rails application runed on mod_rails</title>
      <link>http://snippets.dzone.com/posts/show/5543</link>
      <description>&lt;br /&gt;&lt;code&gt;&lt;br /&gt;amespace :passenger do&lt;br /&gt;  desc "Restart Application"&lt;br /&gt;  task :restart do&lt;br /&gt;    puts `touch tmp/restart.txt`&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 27 May 2008 12:26:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5543</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title> Easier path construction using overloaded /</title>
      <link>http://snippets.dzone.com/posts/show/5285</link>
      <description>&lt;br /&gt;Especially when writing rake tasks where a lot of path construction code is written the following overloading of the / operator makes the code more readable.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;class String&lt;br /&gt;  def /(other)&lt;br /&gt;    File.join(self,other)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# and you can write&lt;br /&gt;#   path = all/along/the/watch/tower&lt;br /&gt;# instead of &lt;br /&gt;#   path = "#{all}/#{along}/#{the}/#{watch}/#{tower}"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 28 Mar 2008 15:15:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5285</guid>
      <author>shmul (Shmulik Regev)</author>
    </item>
    <item>
      <title>rake task to rename views to rails 2.0 format </title>
      <link>http://snippets.dzone.com/posts/show/5262</link>
      <description>// This task will rename your files to the rails 2.0 format, using git mv. Add it to /lib/tasks/rails.rake&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace 'views' do&lt;br /&gt;  desc 'Renames all .rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder, and .haml to .html.haml'&lt;br /&gt;  task 'rename' do&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.rhtml').each do |file|&lt;br /&gt;      puts `git mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.rxml').each do |file|&lt;br /&gt;      puts `git mv #{file} #{file.gsub(/\.rxml$/, '.xml.builder')}`&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.rjs').each do |file|&lt;br /&gt;      puts `git mv #{file} #{file.gsub(/\.rjs$/, '.js.rjs')}`&lt;br /&gt;    end&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.haml').each do |file|&lt;br /&gt;      puts `git mv #{file} #{file.gsub(/\.haml$/, '.html.haml')}`&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 20 Mar 2008 03:11:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5262</guid>
      <author>caffo ()</author>
    </item>
    <item>
      <title>create new rails rake task</title>
      <link>http://snippets.dzone.com/posts/show/5185</link>
      <description>Create new task for /unit/helpers/*_test.rb&lt;br /&gt;&lt;br /&gt;Rakefile &lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace :test do&lt;br /&gt;  Rake::TestTask.new(:helpers) do |t|&lt;br /&gt;    t.libs &lt;&lt; "test"&lt;br /&gt;    t.pattern = 'test/unit/helper/*_test.rb'&lt;br /&gt;    t.verbose = true&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  Rake::Task['test:helpers'].invoke&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 28 Feb 2008 15:02:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5185</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>Active Record YAML Backup Solution - Drop in rake task and config file to backup db and directorys of your choice (user uploaded files) 

</title>
      <link>http://snippets.dzone.com/posts/show/4777</link>
      <description>EZ drop in backup rake task for your rails projects - works well - 5 - 10 min set up, one rake file and one config file&lt;br /&gt;backs up db and any directory's to any number of servers with rsync&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;BSD License or whatever, but it would be cool if you told me your using it&lt;br /&gt;2007 ISS http://industrialstrengthinc.com&lt;br /&gt;&lt;br /&gt;this is a sample config file and a rake task you can drop into any rails project to do backups, easy to automate.&lt;br /&gt;Backs up your specified environment db to activerecord yml files (one per table) and zips them up in a human readable timestamped file&lt;br /&gt;syncs that and any other set of arbitrary directory's to any number of arbitrary servers with rsync&lt;br /&gt;be sure to set ssh key based logins&lt;br /&gt;to run: rake backup&lt;br /&gt;also: rake backup:db, rake backup:restoredb (promts for a file created by backup:db), rake backup:push (to push out what u got)&lt;br /&gt;note: this uses something like 30 lines of code from some blog site I got it from that I cant recall, yay for that guy, thanks&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;## example crontab entry:&lt;br /&gt;&lt;br /&gt;3 * * * * cd /rails_deployment_dir/current &amp;&amp; nice rake backup RAILS_ENV=production &gt;&gt; /rails_deployment_dir/production_backup_system.log&lt;br /&gt;&lt;br /&gt;## config file - goes in config/backup.yml&lt;br /&gt;&lt;br /&gt;production: &lt;br /&gt;  dirs: &lt;br /&gt;   - db/backups&lt;br /&gt;   - public/uploaded_images&lt;br /&gt;  servers: &lt;br /&gt;    -  name: backup server number 1&lt;br /&gt;       host: gridserver.com&lt;br /&gt;       port: 22&lt;br /&gt;       user: blah@whatever.com&lt;br /&gt;       dir: /home/blah/backups&lt;br /&gt;    -  name: backup server two&lt;br /&gt;       host: kradradio.com&lt;br /&gt;       port: 22&lt;br /&gt;       user: kraduser&lt;br /&gt;       dir: /home/kraduser/backups_from_my_rails_proj&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;development: &lt;br /&gt;  dirs: &lt;br /&gt;   - db/backups&lt;br /&gt;   - public/uploaded_images&lt;br /&gt;  servers: &lt;br /&gt;    -  name: local self&lt;br /&gt;       host: localhost&lt;br /&gt;       port: 5222&lt;br /&gt;       user: oneman&lt;br /&gt;       dir: /home/oneman/Documents/development_backup&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## rake file lib/tasks/backup.rake&lt;br /&gt;&lt;br /&gt;desc "Backup Everything Specified in config/backup.yml"&lt;br /&gt;task :backup =&gt; [ "backup:db",  "backup:push"]&lt;br /&gt;&lt;br /&gt;namespace :backup do&lt;br /&gt; &lt;br /&gt;    RAILS_APPDIR = RAILS_ROOT.sub("/config/..","")&lt;br /&gt;    &lt;br /&gt;   def interesting_tables&lt;br /&gt;     ActiveRecord::Base.connection.tables.sort.reject! do |tbl|&lt;br /&gt;       ['schema_info', 'sessions', 'public_exceptions'].include?(tbl)&lt;br /&gt;     end&lt;br /&gt;   end&lt;br /&gt;  &lt;br /&gt;   desc "Push backup to remote server"&lt;br /&gt;   task :push  =&gt; [:environment] do &lt;br /&gt;      FileUtils.chdir(RAILS_APPDIR)&lt;br /&gt;      backup_config = YAML::load( File.open( 'config/backup.yml' ) )[RAILS_ENV]&lt;br /&gt;      for server in backup_config["servers"]&lt;br /&gt;       puts "Backing up #{RAILS_ENV} directorys #{backup_config['dirs'].join(', ')} to #{server['name']}"&lt;br /&gt;       puts "Time is " + Time.now.rfc2822 + "\n\n"&lt;br /&gt;         for dir in backup_config["dirs"]&lt;br /&gt;          local_dir = RAILS_APPDIR + "/" + dir + "/"&lt;br /&gt;          remote_dir = server['dir'] + "/" + dir.split("/").last + "/"&lt;br /&gt;          puts "Syncing #{local_dir} to #{server['host']}#{remote_dir}"&lt;br /&gt;          sh "/usr/bin/rsync -avz -e 'ssh -p#{server['port']} ' #{local_dir} #{server['user']}@#{server['host']}:#{remote_dir}"&lt;br /&gt;         end&lt;br /&gt;       puts "Completed backup to #{server['name']}\n\n"&lt;br /&gt;      end&lt;br /&gt;   end&lt;br /&gt;&lt;br /&gt;    task :storedb =&gt; :environment do &lt;br /&gt;&lt;br /&gt;      backupdir = RAILS_APPDIR + '/db/backup'&lt;br /&gt;      FileUtils.mkdir_p(backupdir)&lt;br /&gt;      FileUtils.chdir(backupdir)&lt;br /&gt;      puts "Dumping database to activerecord yaml files in #{backupdir}"&lt;br /&gt;      interesting_tables.each do |tbl|&lt;br /&gt;&lt;br /&gt;        klass = tbl.classify.constantize&lt;br /&gt;        puts "Writing #{tbl}..."&lt;br /&gt;        File.open("#{tbl}.yml", 'w+') { |f| YAML.dump klass.find(:all).collect(&amp;:attributes), f }      &lt;br /&gt;      end&lt;br /&gt;      puts "Database Dumped.\n\n"&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    desc "Dump Current Environment Db to file"    &lt;br /&gt;    task :db =&gt; [:environment, :storedb ] do&lt;br /&gt;      backupdir = RAILS_APPDIR + '/db/backup'&lt;br /&gt;      archivedir = RAILS_APPDIR + '/db/backups'&lt;br /&gt;      backup_filename = "#{RAILS_ENV}_db_backup_#{Time.now.strftime("%B.%d.%Y_at_%I.%M.%S%p_%Z")}.tar.bz2"&lt;br /&gt;      FileUtils.mkdir_p(archivedir)&lt;br /&gt;      puts "Archiving #{backupdir} yaml files to #{backup_filename}\n\n"&lt;br /&gt;      `tar -C #{backupdir} -cjf #{backup_filename} *`&lt;br /&gt;      `mv #{backup_filename} #{archivedir}`&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    desc "Restore Current Environment Db from a file"    &lt;br /&gt;    task :restoredb =&gt; [:environment] do &lt;br /&gt;        backupdir = RAILS_APPDIR + '/db/backup'&lt;br /&gt;        archivedir = RAILS_APPDIR + '/db/backups'&lt;br /&gt;        print "Input a file to load into the db: #{archivedir}/"&lt;br /&gt;        backup_filename = STDIN.gets.chomp&lt;br /&gt;        puts "Loading backup file: #{backup_filename}"&lt;br /&gt;        FileUtils.chdir(archivedir)&lt;br /&gt;        `tar -xjf #{backup_filename}`&lt;br /&gt;        `mv *.yml #{backupdir}`&lt;br /&gt;        FileUtils.mkdir_p(backupdir)&lt;br /&gt;        FileUtils.chdir(backupdir)&lt;br /&gt;    &lt;br /&gt;        interesting_tables.each do |tbl|&lt;br /&gt;        puts "Clearing #{tbl} table.."&lt;br /&gt;        ActiveRecord::Base.connection.execute "TRUNCATE #{tbl}"&lt;br /&gt;        puts "Loading #{tbl} backup file..."&lt;br /&gt;        table = YAML.load_file("#{tbl}.yml")        &lt;br /&gt;&lt;br /&gt;        if table.length &gt; 0 &amp;&amp; table.first.key?("id")&lt;br /&gt;            highestid = 0&lt;br /&gt;            table.each do |fixture|&lt;br /&gt;             if fixture["id"] &gt; highestid&lt;br /&gt;                highestid = fixture["id"]&lt;br /&gt;             end&lt;br /&gt;            end&lt;br /&gt;&lt;br /&gt;            ActiveRecord::Base.connection.execute "SELECT setval('#{tbl}_id_seq',#{highestid})"&lt;br /&gt;            puts "Setting #{tbl}_id sequence to #{highestid}"&lt;br /&gt;        end&lt;br /&gt;         &lt;br /&gt;        #klass = tbl.classify.constantize&lt;br /&gt;        ActiveRecord::Base.transaction do &lt;br /&gt;        &lt;br /&gt;          puts "Inserting #{table.length} values into #{tbl}"&lt;br /&gt;          table.each do |fixture|&lt;br /&gt;            ActiveRecord::Base.connection.execute "INSERT INTO #{tbl} (#{fixture.keys.join(",")}) VALUES (#{fixture.values.collect { |value| ActiveRecord::Base.connection.quote(value) }.join(",")})", 'Fixture Insert'&lt;br /&gt;          end        &lt;br /&gt;          puts "#{tbl} table restored.\n\n"&lt;br /&gt;        end&lt;br /&gt;       end&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 16 Nov 2007 04:38:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4777</guid>
      <author>rawdod (David Richards)</author>
    </item>
    <item>
      <title>Save db data to fixture files</title>
      <link>http://snippets.dzone.com/posts/show/4729</link>
      <description>rake db:fixtures:dump_all &lt;br /&gt;&#1086;&#1085; &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1080;&#1090; &#1074;&#1089;&#1077; &#1076;&#1072;&#1085;&#1085;&#1099;&#1077; &#1080;&#1079; &#1074;&#1072;&#1096;&#1080;&#1093; &#1090;&#1072;&#1073;&#1083;&#1080;&#1094; development &#1073;&#1072;&#1079;&#1099; &#1074; &#1103;&#1084;&#1083;&#1099; &#1076;&#1083;&#1103; &#1090;&#1077;&#1089;&#1090;&#1086;&#1074; rake &lt;br /&gt;&lt;br /&gt;db:fixtures:dump_references &lt;br /&gt;["areas","countries"]&lt;br /&gt;&#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1080;&#1090; &#1090;&#1086;&#1083;&#1100;&#1082;&#1086; &#1090;&#1077; &#1090;&#1072;&#1073;&#1083;&#1080;&#1094;&#1099; &#1082;&#1086;&#1090;&#1086;&#1088;&#1099; &#1077;&#1087;&#1088;&#1086;&#1087;&#1080;&#1089;&#1072;&#1085;&#1099; &#1091; &#1085;&#1077;&#1075;&#1086; &#1074; &#1082;&#1086;&#1085;&#1092;&#1080;&#1075;&#1077;, &#1074; &#1076;&#1072;&#1085;&#1085;&#1086;&#1084; &#1089;&#1083;&#1091;&#1095;&#1072;&#1077; &#1101;&#1090;&#1086; &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace :db do&lt;br /&gt;  namespace :fixtures do&lt;br /&gt;&lt;br /&gt;    desc 'Create YAML test fixtures from data in an existing database.&lt;br /&gt;Defaults to development database. Set RAILS_ENV to override.'&lt;br /&gt;    task :dump_all =&gt; :environment do&lt;br /&gt;      sql = "SELECT * FROM %s"&lt;br /&gt;      skip_tables = ["schema_info"]&lt;br /&gt;      ActiveRecord::Base.establish_connection(:development)&lt;br /&gt;      (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|&lt;br /&gt;        i = "000"&lt;br /&gt;        File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file|&lt;br /&gt;          data = ActiveRecord::Base.connection.select_all(sql % table_name)&lt;br /&gt;          file.write data.inject({}) { |hash, record|&lt;br /&gt;            hash["#{table_name}_#{i.succ!}"] = record&lt;br /&gt;            hash&lt;br /&gt;          }.to_yaml&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  namespace :fixtures do&lt;br /&gt;    desc 'Create YAML test fixtures for references. Defaults to development database. &lt;br /&gt;    Set RAILS_ENV to override.'&lt;br /&gt;    task :dump_references =&gt; :environment do&lt;br /&gt;      sql = "SELECT * FROM %s"&lt;br /&gt;      dump_tables = ["areas","countries"]&lt;br /&gt;      ActiveRecord::Base.establish_connection(:development)&lt;br /&gt;      dump_tables.each do |table_name|&lt;br /&gt;        i = "000"&lt;br /&gt;        file_name = "#{RAILS_ROOT}/test/fixtures/#{table_name}.yml"&lt;br /&gt;        p "Fixture save for table #{table_name} to #{file_name}"&lt;br /&gt;        File.open(file_name, 'w') do |file|&lt;br /&gt;          data = ActiveRecord::Base.connection.select_all(sql % table_name)&lt;br /&gt;          file.write data.inject({}) { |hash, record|&lt;br /&gt;            hash["#{table_name}_#{i.succ!}"] = record&lt;br /&gt;            hash&lt;br /&gt;          }.to_yaml&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 02 Nov 2007 09:30:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4729</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>View all colors from a set of stylesheets</title>
      <link>http://snippets.dzone.com/posts/show/4616</link>
      <description>Rake task to grep out colors from a set of CSS stylesheets and display them on a web page. Default configuration works for OS X Safari and a Rails application.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;BROWSER = "/Applications/Safari.app/Contents/MacOS/Safari"&lt;br /&gt;CSS_FILES = "#{RAILS_ROOT}/public/stylesheets/**/*.css"&lt;br /&gt;&lt;br /&gt;task :colors do&lt;br /&gt;  require "tempfile"&lt;br /&gt;  colors = Dir[CSS_FILES].map(&amp;File.method(:read)).join.scan(/\#[0-9a-f]{3,6}/i).map{|c| c.upcase}.uniq&lt;br /&gt;  Tempfile.open "colors" do |f|&lt;br /&gt;    f.write &lt;&lt;-EOHTML&lt;br /&gt;    &lt;html&gt;&lt;br /&gt;      &lt;head&gt;&lt;br /&gt;        &lt;style type="text/css"&gt;&lt;br /&gt;          div { width: 50px; height: 50px; display: inline-block }&lt;br /&gt;        &lt;/style&gt;&lt;br /&gt;      &lt;/head&gt;&lt;br /&gt;      &lt;body&gt;&lt;br /&gt;        #{colors.map{|clr| &lt;br /&gt;          "&lt;div style='background: #{clr}'&gt;&amp;nbsp;&lt;/div&gt; #{clr} &lt;br /&gt;"&lt;br /&gt;        }.join}&lt;br /&gt;      &lt;/body&gt;&lt;br /&gt;    &lt;/html&gt;&lt;br /&gt;    EOHTML&lt;br /&gt;    system BROWSER, f.path&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 04 Oct 2007 17:19:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4616</guid>
      <author>bradediger (Brad Ediger)</author>
    </item>
    <item>
      <title>rcov rake task for rails project</title>
      <link>http://snippets.dzone.com/posts/show/4525</link>
      <description>This task will create a folder (doc/coverage) then run all of your tests and produce HTML with code coverage information in that folder. If you are on a mac it will even open the index.html file up for you automatically&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# this requires the RCOV gem to be installed on your system&lt;br /&gt;namespace :test do&lt;br /&gt;  desc "Generate code coverage with rcov"&lt;br /&gt;  task :coverage do&lt;br /&gt;    rm_f "doc/coverage/coverage.data"&lt;br /&gt;    rm_f "doc/coverage"&lt;br /&gt;    mkdir "doc/coverage"&lt;br /&gt;    rcov = %(rcov --rails --aggregate doc/coverage/coverage.data --text-summary -Ilib --html -o doc/coverage test/**/*_test.rb)&lt;br /&gt;    system rcov&lt;br /&gt;    system "open doc/coverage/index.html" if PLATFORM['darwin']&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Sep 2007 16:13:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4525</guid>
      <author>akbloom (Andrew Bloom)</author>
    </item>
    <item>
      <title>Dump models into fixtures.</title>
      <link>http://snippets.dzone.com/posts/show/4468</link>
      <description>This snippet of code will look in app/models for all models, then dump their contents into the corresponding fixture file found in test/fixtures. At the moment, it can not differentiate between regular models and mailer models, so just remove the extension then run the script. Same goes for models you don't want dumped. I'm working on adding only and except as well.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'find'&lt;br /&gt;&lt;br /&gt;namespace :db do&lt;br /&gt;  namespace :fixtures do&lt;br /&gt;    desc 'Dumps all models into fixtures.'&lt;br /&gt;    task :dump =&gt; :environment do&lt;br /&gt;      models = []&lt;br /&gt;      Find.find(RAILS_ROOT + '/app/models') do |path|&lt;br /&gt;        unless File.directory?(path) then models &lt;&lt; path.match(/(\w+).rb/)[1] end&lt;br /&gt;      end&lt;br /&gt;  &lt;br /&gt;      puts "Found models: " + models.join(', ')&lt;br /&gt;      &lt;br /&gt;      models.each do |m|&lt;br /&gt;        puts "Dumping model: " + m&lt;br /&gt;        model = m.capitalize.constantize&lt;br /&gt;        entries = model.find(:all, :order =&gt; 'id ASC')&lt;br /&gt;        &lt;br /&gt;        formatted, increment, tab = '', 1, '  '&lt;br /&gt;        entries.each do |a|&lt;br /&gt;          formatted += m + '_' + increment.to_s + ':' + "\n"&lt;br /&gt;          increment += 1&lt;br /&gt;          &lt;br /&gt;          a.attributes.each do |column, value|&lt;br /&gt;            formatted += tab&lt;br /&gt;            &lt;br /&gt;            match = value.to_s.match(/\n/)&lt;br /&gt;            if match&lt;br /&gt;              formatted += column + ': |' + "\n"&lt;br /&gt;              &lt;br /&gt;              value.to_a.each do |v|&lt;br /&gt;                formatted += tab + tab + v&lt;br /&gt;              end&lt;br /&gt;            else&lt;br /&gt;              formatted += column + ': ' + value.to_s&lt;br /&gt;            end&lt;br /&gt;            &lt;br /&gt;            formatted += "\n"&lt;br /&gt;          end&lt;br /&gt;                    &lt;br /&gt;          formatted += "\n"&lt;br /&gt;        end&lt;br /&gt;      &lt;br /&gt;        model_file = RAILS_ROOT + '/test/fixtures/' + m.pluralize + '.yml'&lt;br /&gt;        &lt;br /&gt;        File.exists?(model_file) ? File.delete(model_file) : nil&lt;br /&gt;        File.open(model_file, 'w') {|f| f &lt;&lt; formatted}&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 26 Aug 2007 22:26:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4468</guid>
      <author>MichaelBoutros (Michael Boutros)</author>
    </item>
  </channel>
</rss>
