<?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>confabulus &#187; configuration</title>
	<atom:link href="http://blog.confabulus.com/category/rails/configuration/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.confabulus.com</link>
	<description>rails, coding, and the goings on at confabulus</description>
	<lastBuildDate>Fri, 19 Feb 2010 22:08:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making your Plugin or Gem configurable</title>
		<link>http://blog.confabulus.com/2008/12/30/making-your-plugin-or-gem-configurable/</link>
		<comments>http://blog.confabulus.com/2008/12/30/making-your-plugin-or-gem-configurable/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 02:41:32 +0000</pubDate>
		<dc:creator>gaffo</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[test::unit]]></category>

		<guid isPermaLink="false">http://blog.confabulus.com/?p=105</guid>
		<description><![CDATA[Recently I added a configuration mechanism to Webrat. It was surprisingly easy, and mainly copied from rails core. I would suggest adding somthing like this to any plugin that has more than a few features or ones that users have asked to have turned off.
First off you&#8217;re going to have to create the actual configuration [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I added a configuration mechanism to Webrat. It was surprisingly easy, and mainly copied from rails core. I would suggest adding somthing like this to any plugin that has more than a few features or ones that users have asked to have turned off.</p>
<p>First off you&#8217;re going to have to create the actual configuration object. There are a few good ways to do this. One is to use a <a href="http://toolmantim.com/article/2007/5/18/consolidating_your_apps_constants">config module</a>, another is to create a configuration object that is accessible via a singleton method.</p>
<p>I&#8217;m going to go with the second one, a configuration object.</p>
<p>Toss this one in lib/configuration.rb (A simplification of <a href="http://github.com/brynary/webrat/tree/2c51d908301e23a8594eda49f0d64ce197b3e842/lib/webrat/core/configuration.rb">Code</a> | <a href="http://rdocul.us/repos/webrat/master/classes/Webrat/Configuration.html">RDoc</a>) </p>
<pre class="brush: ruby">
module Plugin

  # Configures Plugin.
  def self.configure(configuration = Plugin::Configuration.new)
    yield configuration if block_given?
    @@configuration = configuration
  end

  def self.configuration # :nodoc:
    @@configuration ||= Plugin::Configuration.new
  end

  # Plugin can be configured using the Plugin.configure method. For example:
  #
  #   Plugin.configure do |config|
  #     config.show_whiny_errors = false
  #   end
  class Configuration

    # Should whiny error messages be shown?
    attr_writer :show_whiny_errors

    def initialize # :nodoc:
      # set your defaults in here
      self.show_whiny_errors = true
      # put as much as you want in here
    end

    # some syntactic sugar for you, the coder
    def show_whiny_errors? #:nodoc:
      @show_whiny_erorrs ? true : false
    end

  end

end
</pre>
<p>Okay, now we need to test the config object itself. This is why it&#8217;s nice to make an object just to house the config, it&#8217;s easy to test. What do we test? Well defaults and accessors for two!</p>
<p>(The following lifted from <a href="http://github.com/brynary/webrat/tree/2c51d908301e23a8594eda49f0d64ce197b3e842/spec/webrat/core/configuration_spec.rb">Code</a>) (sorry this is in rspec, it&#8217;s not hard to do in test::unit)</p>
<pre class="brush: ruby">
require File.expand_path(File.dirname(__FILE__) + &#039;/../../spec_helper&#039;)

describe Plugin::Configuration do
  # define matchers for testing
  predicate_matchers[:show_whiny_errors] = :show_whiny_errors?

  it &#039;should show whiny errors by default&#039; do
    config = Plugin::Configuration.new
    config.should show_whiny_errors?
  end

  it &#039;should be configurable with a block&#039; do
    Plugin.configure do |config|
      config.show_whiny_errors = false
    end

    config = Plugin.configuration
    config.should_not show_whiny_errors?
  end

end
</pre>
<p>Now we need to do some stuff to make it nicer for our other users to test. Put the following in your test_helper or spec helper. It will allow you to clear your config after each test. Nice to have to to avoid messy test issues.</p>
<p>(The following lifted from <a href="http://github.com/brynary/webrat/tree/2c51d908301e23a8594eda49f0d64ce197b3e842/spec/spec_helper.rb">Code</a>)</p>
<pre class="brush: ruby">
module Plugin
  @@previous_config = nil

  def self.cache_config_for_test
    @@previous_config = Plugin.configuration.clone
  end

  def self.reset_for_test
    @@configuration = @@previous_config if @@previous_config
  end
end

# configure your test runner / spec runner to always clear the config
Spec::Runner.configure do |config|

  config.before :each do
    Plugin.cache_config_for_test
  end

  config.after :each do
    Plugin.reset_for_test
  end
end
</pre>
<p>This last bit is somewhat hard to do in test::unit as it is harder to hook into the setup (you only get one in the call chain). I&#8217;m willing to take some help on cleaning this one up for test::unit. Currently I have just been putting it in the setup / teardown for each test file.</p>
<p>Finally you need to make use of this in tests, fortunately that is quite easy. Just:</p>
<pre class="brush: ruby">
describe SomeObject do
    it &#039;it shouldn&#039;t do it when whiny nils are off&#039; do
      Plugin.configure do |config|
        config.show_whiny_errors = false
      end
      object.should_not_receive(:log)

      object.do_somthing_that_usually_complains
    end
end
</pre>
<p>Finally, anywhere in your plugin that you think somthing is whiny, just check the config before using it like this:</p>
<pre class="brush: ruby">
log(&amp;quot;you should really fix this&amp;quot;) if Plugin.configuration.show_whiny_errors?
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.confabulus.com/2008/12/30/making-your-plugin-or-gem-configurable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>generator_missing plugin release</title>
		<link>http://blog.confabulus.com/2008/12/22/generator_missing-plugin-release/</link>
		<comments>http://blog.confabulus.com/2008/12/22/generator_missing-plugin-release/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 16:16:27 +0000</pubDate>
		<dc:creator>gaffo</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.confabulus.com/?p=95</guid>
		<description><![CDATA[I just posted my initial cut of my generator_missing plugin. This plugin is meant to be a repository of additional generators to help workflow. The current ones are:

Library: Generates a non active record ruby object and a test class.

lib/library_name.rb
test/unit/library_name_test.rb


Module: Generates a basic module under lib and its tests.

lib/module_name.rb
test/unit/module_name_test.rb, with a mock class that mixes in [...]]]></description>
			<content:encoded><![CDATA[<p>I just posted my initial cut of my generator_missing plugin. This plugin is meant to be a repository of additional generators to help workflow. The current ones are:</p>
<ul>
<li>Library: Generates a non active record ruby object and a test class.
<ul>
<li>lib/library_name.rb</li>
<li>test/unit/library_name_test.rb</li>
</ul>
</li>
<li>Module: Generates a basic module under lib and its tests.
<ul>
<li>lib/module_name.rb</li>
<li>test/unit/module_name_test.rb, with a mock class that mixes in the library</li>
</ul>
</li>
<li>Base Generator: Generates a generator (mmm meta) with a template, usage and manifest.
<ul>
<li>lib/generators/generator_name/generator_name_generator.rb</li>
<li>lib/generators/generator_name/USAGE</li>
<li>lib/generators/generator_name/templates</li>
</ul>
</li>
</ul>
<p>The plugin is at: <a href="http://github.com/gaffo/generator_missing">http://github.com/gaffo/generator_missing</a> / git://github.com/gaffo/generator_missing.git<br />
Lighthouse at <a href="http://gaffo.lighthouseapp.com/projects/21321-generator_missing/overview">http://gaffo.lighthouseapp.com/projects/21321-generator_missing/overview</a>.</p>
<p>I am currently taking both suggestions and pull requests for generators that should be added.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.confabulus.com/2008/12/22/generator_missing-plugin-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>hiding production database info from source control with capistrano</title>
		<link>http://blog.confabulus.com/2008/10/14/hiding-production-database-info-from-source-control-with-capistrano/</link>
		<comments>http://blog.confabulus.com/2008/10/14/hiding-production-database-info-from-source-control-with-capistrano/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 14:09:53 +0000</pubDate>
		<dc:creator>gaffo</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.confabulus.com/?p=40</guid>
		<description><![CDATA[Whether you are working on an open source app or an enterprise app, it is a good idea to keep the production database connection information out of source control. To do so, add the following to your deploy.rb file:

task  verwrite_database_yml_file do
  run &#34;[ -f /var/rails/#{application}/database.yml ] &#38;amp;amp;amp;amp;amp;&#38;amp;amp;amp;amp;amp; cp -f /var/rails/#{application}/database.yml #{latest_release}/config/ &#124;&#124; echo [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you are working on an open source app or an enterprise app, it is a good idea to keep the production database connection information out of source control. To do so, add the following to your deploy.rb file:</p>
<pre class="brush: ruby">
task <img src='http://blog.confabulus.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> verwrite_database_yml_file do
  run &quot;[ -f /var/rails/#{application}/database.yml ] &amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp; cp -f /var/rails/#{application}/database.yml #{latest_release}/config/ || echo &#039;database.yml was not overwritten&#039;&quot;
end
after &quot;deploy:update_code&quot;, <img src='http://blog.confabulus.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> verwrite_database_yml_file
</pre>
<p>And place a database.yml file containing only your production connection information in the same directory as current and shared (eg the deploy_to directory). In fact I typically take the production information out of the config/database.yml entirely.</p>
<p>When deploy runs, if it finds a database.yml file in the deploy_to directory, it will copy it into config before migrating or starting the application. You can use this task to copy other configuration files that you want to keep out of source control as well, but I think its a good idea to only have the database connect info and host names change between deployments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.confabulus.com/2008/10/14/hiding-production-database-info-from-source-control-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ruby on rails (2.0.1, 2.0.2) and oracle on FC8</title>
		<link>http://blog.confabulus.com/2008/06/04/ruby-on-rails-201-202-and-oracle-on-fc8/</link>
		<comments>http://blog.confabulus.com/2008/06/04/ruby-on-rails-201-202-and-oracle-on-fc8/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 02:58:16 +0000</pubDate>
		<dc:creator>gaffo</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://blog.confabulus.com/?p=5</guid>
		<description><![CDATA[Get the following rpm&#8217;s from oracle

oracle-instantclient-basic-10.2.0.3-1.i386.rpm
oracle-instantclient-devel-10.2.0.3-1.i386.rpm

(Note: this should work fine with the newer versions as well)
As root

cd PATH_TO_RPMS
rpm -ivh oracle-instantclient-basic-10.2.0.3-1.i386.rpm oracle-instantclient-devel-10.2.0.3-1.i386.rpm
echo /usr/lib/oracle/10.2.0.3/client/lib/ &#62; /etc/ld.so.conf.d/oracle-instant-client-i386.conf

This last step, the echo, is a bit of magic. The conf files in /etc/ld.so.conf.d are run before each command is invoked to set your library path. The enviroment variable $LD_LIBRARY_PATH overrides [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Get the following rpm&#8217;s from oracle</strong></p>
<ul>
<li>oracle-instantclient-basic-10.2.0.3-1.i386.rpm</li>
<li>oracle-instantclient-devel-10.2.0.3-1.i386.rpm</li>
</ul>
<p>(Note: this should work fine with the newer versions as well)</p>
<p><strong>As root</strong></p>
<pre class="brush: bash">
cd PATH_TO_RPMS
rpm -ivh oracle-instantclient-basic-10.2.0.3-1.i386.rpm oracle-instantclient-devel-10.2.0.3-1.i386.rpm
echo /usr/lib/oracle/10.2.0.3/client/lib/ &gt; /etc/ld.so.conf.d/oracle-instant-client-i386.conf
</pre>
<p>This last step, the echo, is a bit of magic. The conf files in /etc/ld.so.conf.d are run before each command is invoked to set your library path. The enviroment variable $LD_LIBRARY_PATH overrides these. You won&#8217;t see the contents of these files in your $LD_LIBRARY_PATH, but the application will. If your distribution doesn&#8217;t have an /etc/ld.so.conf.d directory, you can just add /usr/lib/oracle/10.2.0.3/client/lib to your LD_LIBRARY_PATH inthe /etc/profile, ~/.bash_profile, or any of the other more common places.</p>
<p>Now you need to find the latest ruby-oci8, check <a href="http://ar.rubyonrails.com/">http://ar.rubyonrails.com/</a> and put it in /usr/local/src/</p>
<pre class="brush: bash">
wget http://rubyforge.org/frs/download.php/36134/ruby-oci8-1.0.1.tar.gz
tar -xzvf ruby-oci8-1.0.1.tar.gz
cd ruby-oci8-1.0.1
ruby setup.rb config
make
make install
</pre>
<p>The previous versions of oci8 and ora instant clients required that you make several symlinks, and was a pain to set up. With the current oci8 and the instant clients on your LD_LIBRARY_PATH, the compile and install should work just fine.</p>
<p>With rails 2.1 out, the activerecord-oracle-adapter is no longer hosted on gems.rubyonrails.org. You can see this with a &#8220;gem list -r &#8211;source http://gems.rubyonrails.org&#8221;. So you have to do the ugly method of directly grabbing the adapter yourself. It is very easy though:</p>
<pre class="brush: bash">
wget -P /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/  http://svn.rubyonrails.org/rails/adapters/oracle/lib/active_record/connection_adapters/oracle_adapter.rb
</pre>
<p>That&#8217;s it. Just remember to make sure that you grab the right versions of everything.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.confabulus.com/2008/06/04/ruby-on-rails-201-202-and-oracle-on-fc8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
