<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Innovative Thought &#187; YAML</title>
	<atom:link href="http://innovativethought.net/tag/yaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://innovativethought.net</link>
	<description>think. code. design. innovate.</description>
	<lastBuildDate>Fri, 13 Jan 2012 16:12:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='innovativethought.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Innovative Thought &#187; YAML</title>
		<link>http://innovativethought.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://innovativethought.net/osd.xml" title="Innovative Thought" />
	<atom:link rel='hub' href='http://innovativethought.net/?pushpress=hub'/>
		<item>
		<title>Making Configuration Files with YAML: Revised</title>
		<link>http://innovativethought.net/2009/01/02/making-configuration-files-with-yaml-revised/</link>
		<comments>http://innovativethought.net/2009/01/02/making-configuration-files-with-yaml-revised/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 02:27:08 +0000</pubDate>
		<dc:creator>Tim Knight</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[YAML]]></category>

		<guid isPermaLink="false">http://innovativethought.wordpress.com/2009/01/03/making-configuration-files-with-yaml-revised/</guid>
		<description><![CDATA[So back in July 2007 I posted a blog on making configuration files with YAML, and I&#8217;ve been noticing a lot of readership on the old article. Because it seems that a lot of people are reading it I felt it was important to show how I apply this nowadays. First I put my config.yml [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=innovativethought.net&amp;blog=965151&amp;post=105&amp;subd=innovativethought&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So back in July 2007 I posted a blog <a href="http://blog.innovativethought.net/2007/07/25/making-configuration-files-with-yaml/">on making configuration files with YAML</a>, and I&#8217;ve been noticing a lot of readership on the old article. Because it seems that a lot of people are reading it I felt it was important to show how I apply this nowadays.</p>
<p>First I put my <kbd>config.yml</kbd> file within the <kbd>/config/</kbd> directory within my Rails application. It looks something like this:</p>
<pre><code>development: &amp;non_production_settings
  :google_analytics:
    :api_key: "[Enter Google ID]"
  :site:
    :title: "[Title]"
    :address: "http://localhost:3000/"

test:
  &lt;&lt;: *non_production_settings

production:
  :google_analytics:
    :api_key: "[Enter Google ID]"
  :site:
    :title: "[Title]"
    :address: "[Address]"</code></pre>
<p>Then, I create a new file called <kbd>load_config.rb</kbd> within the <kbd>/config/initializers</kbd> directory. You can name the file whatever you want &#8211; that&#8217;s just what I call it. This is where the actually YAML loading is going to happen &#8211; and this is what it looks like:</p>
<pre><code>raw_config = File.read(RAILS_ROOT + "/config/config.yml")
APP_CONFIG = YAML.load(raw_config)[RAILS_ENV]</code></pre>
<p>Now any time I want to all one of these variables I just call it like:</p>
<pre><code>&lt;%= APP_CONFIG[:site][:title] %&gt;</code></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/innovativethought.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/innovativethought.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/innovativethought.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/innovativethought.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/innovativethought.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/innovativethought.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/innovativethought.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/innovativethought.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=innovativethought.net&amp;blog=965151&amp;post=105&amp;subd=innovativethought&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://innovativethought.net/2009/01/02/making-configuration-files-with-yaml-revised/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2722012beb9afcad75df5c9f2229fd8c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Tim Knight</media:title>
		</media:content>
	</item>
		<item>
		<title>Making Configuration Files with YAML</title>
		<link>http://innovativethought.net/2007/07/25/making-configuration-files-with-yaml/</link>
		<comments>http://innovativethought.net/2007/07/25/making-configuration-files-with-yaml/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 15:30:24 +0000</pubDate>
		<dc:creator>Tim Knight</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[YAML]]></category>

		<guid isPermaLink="false">http://innovativethought.wordpress.com/2007/07/25/making-configuration-files-with-yaml/</guid>
		<description><![CDATA[Update: A newer version of how I load YAML into configuration files in my projects can be found here. Since being introduced to YAML I&#8217;ve loved using it for configuration files in both Ruby and Ruby on Rails. YAML means &#8220;YAML Ain&#8217;t Markup Language&#8221;. Yes, there is an infinite loop in the title &#8211; it&#8217;s programmer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=innovativethought.net&amp;blog=965151&amp;post=46&amp;subd=innovativethought&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> A newer version of how I load YAML into configuration files in my projects can be found <a href="http://blog.innovativethought.net/2009/01/02/making-configuration-files-with-yaml-revised/">here</a>.</p>
<p>Since being introduced to YAML I&#8217;ve loved using it for configuration files in both Ruby and Ruby on Rails.  YAML means &#8220;YAML Ain&#8217;t Markup Language&#8221;.  Yes, there is an infinite loop in the title &#8211; it&#8217;s programmer humor.  Those of you familiar with Ruby on Rails are somewhat familiar with YAML because that is the format of the database.yml configuration file.  So this is a sample of what a YAML file typically looks like:</p>
<pre>development:
	adapter: mysql
	database: project_development
	username: root
	password:
	socket: /tmp/mysql.sock</pre>
<p>This is a snippet out of the database.yml file.  But one of the great things about Ruby is that writing code to read YAML is extremely simple.  Let&#8217;s say I want to make a website configuration file, this is what that might look like:</p>
<pre>config:
	title: My Rails Website
	author: Santa Claus
	email: email@company.com
	css_file: default.css</pre>
<p>The hardest part is thinking about what type of information you want to store in your configuration, the Ruby is extremely easy.  Check it out&#8230;</p>
<p>First we require the YAML library:</p>
<pre>require 'yaml'</pre>
<p>Ok, now we can make a read_config method:</p>
<pre>def read_config
	config = YAML.load_file("config.yaml")
	@title = config["config"]["title"]
	@author = config["config"]["author"]
	@email = config["config"]["email"]
	@css_file = config["config"]["css_file"]
end</pre>
<p>Seriously, that&#8217;s it (of course you need to execute the method).  We just load the YAML into a local variable.  Then we spider down the YAML document using the local variable that we assigned the loaded YAML document.  So where you see &#8220;config&#8221; in quotes that is referring to the &#8220;config:&#8221; within the YAML document.  Of course, were I say &#8220;config.yaml&#8221; you would actually put the path to your specific YAML document.  One the information is loaded, I pull the data I want into a few instance variables making them accessible to my views (in Rails).</p>
<p><em>Update:</em></p>
<p>A more efficient way to do this would be to loop through the hash that is created by the read_config method and just set the key to an instance variable, like so:</p>
<pre>config["config"].each { |key, value| instance_variable_set("@#{key}", value) }</pre>
<p><strong>Update:</strong> A newer version of how I load YAML into configuration files in my projects can be found <a href="http://blog.innovativethought.net/2009/01/02/making-configuration-files-with-yaml-revised/">here</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/innovativethought.wordpress.com/46/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/innovativethought.wordpress.com/46/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/innovativethought.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/innovativethought.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/innovativethought.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/innovativethought.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/innovativethought.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/innovativethought.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/innovativethought.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/innovativethought.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=innovativethought.net&amp;blog=965151&amp;post=46&amp;subd=innovativethought&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://innovativethought.net/2007/07/25/making-configuration-files-with-yaml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2722012beb9afcad75df5c9f2229fd8c?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Tim Knight</media:title>
		</media:content>
	</item>
	</channel>
</rss>
