<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; yaml</title>
	<atom:link href="http://seanbehan.com/tag/yaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Merge a YAML File Into a Single Hash in Ruby</title>
		<link>http://seanbehan.com/ruby/how-to-merge-a-yaml-file-into-a-single-hash-in-ruby/</link>
		<comments>http://seanbehan.com/ruby/how-to-merge-a-yaml-file-into-a-single-hash-in-ruby/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 19:23:09 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1483</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby%2Fhow-to-merge-a-yaml-file-into-a-single-hash-in-ruby%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="How to Merge a YAML File Into a Single Hash in Ruby" data-url="http://seanbehan.com/ruby/how-to-merge-a-yaml-file-into-a-single-hash-in-ruby/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p><script src="https://gist.github.com/1571559.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby/how-to-merge-a-yaml-file-into-a-single-hash-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rake DB Everything, Dump, Destroy, Create, Load</title>
		<link>http://seanbehan.com/ruby-on-rails/rake-db-everything-dump-destroy-create-load/</link>
		<comments>http://seanbehan.com/ruby-on-rails/rake-db-everything-dump-destroy-create-load/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 22:01:10 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[tasks]]></category>
		<category><![CDATA[yaml]]></category>
		<category><![CDATA[yaml_db]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=916</guid>
		<description><![CDATA[I&#8217;m a big fan of the yaml_db plugin. But I don&#8217;t like running rake db:data:load, only to find that my db columns mismatch my model attributes, thus aborting the data import task. To quickly add/remove columns/attributes from a model and rebuild the database with previous db info, I wrote this simple rake task. It saves [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Frake-db-everything-dump-destroy-create-load%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Rake DB Everything, Dump, Destroy, Create, Load" data-url="http://seanbehan.com/ruby-on-rails/rake-db-everything-dump-destroy-create-load/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I&#8217;m a big fan of the yaml_db plugin. But I don&#8217;t like running rake db:data:load, only to find that my db columns mismatch my model attributes, thus aborting the data import task.  To quickly add/remove columns/attributes from a model and rebuild the database with previous db info, I wrote this simple rake task. It saves model records as yaml in db/seandb.yml, and reloads them in the same task but with the db rebuilt. I nest the save method in begin/rescue so that if there are any conflicts the task will continue.</p>
<p>This biggest challenge was to get a list of all the active record models in the Rails app. This problem has been posted a lot and I didn&#8217;t find an easy solution. For now, I just look in the app/models directory and &#8216;classify&#8217; and &#8216;constantize&#8217;  the file name. This will load the model so that I can iterate over all the active record subclasses and call the appropriate Model.find(:all) method. I could maybe do the same w/ all files in the Rails.configuration.load_paths, but my models are, at least for now, under app/models. Plugin models are loaded and available from the rake task if you require the :environment.</p>
<p>It&#8217;s as simple as running</p>
<pre class="wp-code-highlight prettyprint">
rake db:everything
</pre>
<pre class="wp-code-highlight prettyprint">
SAVEDB = &quot;#{RAILS_ROOT}/db/seandb.yml&quot;
namespace :db do
   task :everything =&gt; [:environment, :spit, :drop, :create, :migrate, :populate] do
     desc &quot;spit out model records as yaml, rebuild the database and repopulate the db&quot;
   end

   task :spit do
    Dir[&quot;#{RAILS_ROOT}/app/models/*&quot;].each {|file| (File.basename(file,&quot;.*&quot;).classify.constantize)}
    File.open(SAVEDB, &quot;w&quot;) do |f|
      ActiveRecord::Base.send(:subclasses).each do |model|
        begin
          model.find(:all).each do |record|
              f.write(record.to_yaml)
              print &quot;\twrote #{record.class}\n&quot;
          end
        rescue
        end
      end
    end
   end

   task :populate do
    File.open( SAVEDB ) do |yf|
      YAML.each_document( yf ) do |ydoc|
        begin
          m = ydoc.clone
          m.save
          p &quot;...saved #{m.id}&quot;
        rescue
        end
      end
    end
   end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/rake-db-everything-dump-destroy-create-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manage Fixtures with Yaml DB Plugin for Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/manage-fixtures-with-yaml-db-plugin-for-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/manage-fixtures-with-yaml-db-plugin-for-rails/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 21:20:48 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=527</guid>
		<description><![CDATA[Get the plugin like so&#8230; script/plugin install git://github.com/adamwiggins/yaml_db.git This command will dump your data rake db:data:dump And load it back rake db:data:load Beautiful :) More info here http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/ and http://stackoverflow.com/questions/490507/best-way-to-export-a-database-table-to-a-yaml-file]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fmanage-fixtures-with-yaml-db-plugin-for-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Manage Fixtures with Yaml DB Plugin for Rails" data-url="http://seanbehan.com/ruby-on-rails/manage-fixtures-with-yaml-db-plugin-for-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Get the plugin like so&#8230;</p>
<pre class="wp-code-highlight prettyprint">
script/plugin install git://github.com/adamwiggins/yaml_db.git
</pre>
<p>This command will dump your data</p>
<pre class="wp-code-highlight prettyprint">
rake db:data:dump
</pre>
<p>And load it back</p>
<pre class="wp-code-highlight prettyprint">
rake db:data:load
</pre>
<p>Beautiful :) More info here</p>
<p>http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/</p>
<p>and</p>
<p>http://stackoverflow.com/questions/490507/best-way-to-export-a-database-table-to-a-yaml-file</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/manage-fixtures-with-yaml-db-plugin-for-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

