<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.simonecarletti.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Simone Carletti's Blog</title>
	
	<link>http://www.simonecarletti.com/blog</link>
	<description>Simone Carletti's personal ramblings on programming, syndication, search engines &amp; marketing.</description>
	<lastBuildDate>Wed, 20 Mar 2013 16:45:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.simonecarletti.com/simonecarletti/en" /><feedburner:info uri="simonecarletti/en" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Ruby Whois 3.0</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/ANGk8eNin2I/</link>
		<comments>http://www.simonecarletti.com/blog/2013/03/ruby-whois-3-0/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 16:45:06 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubywhois]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1714</guid>
		<description><![CDATA[Ruby Whois 3.0 has been released today!]]></description>
				<content:encoded><![CDATA[<p><em><a href="http://www.ruby-whois.org/">Whois</a> is an intelligent — pure Ruby — WHOIS client and parser. It provides a flexible and programmable API to query WHOIS servers and look up IP, TLD, and domain WHOIS information. This library was developed to power <a href="https://www.robowhois.com">RoboWhois</a>, <a href="https://www.robodomain.com">RoboDomain</a> and, more recently, <a href="https://dnsimple.com">DNSimple</a>.</em></p>
<p>Let&#8217;s keep this announcement short and simple: <a href="https://rubygems.org/gems/whois">Ruby Whois 3.0</a> has been released today!</p>
<p>Developers tend to assign fancy names to major releases, so I will. For the purpose of this article, I&#8217;ll call this release <strong>Whois 3</strong>.<span id="more-1714"></span></p>
<h2>Changes</h2>
<p>Whois 3 is the result of about 6 month of work. It contains several improvements in addition to an incredible amount of tweaks and updates. If you don&#8217;t believe me, you can have a look at the <a href="https://github.com/weppos/whois/blob/master/CHANGELOG.md">CHANGELOG</a> and you&#8217;ll immediately realize that the Release 3.0 counts more than 50 entries.</p>
<p>The most notable change that will probably affect a few users is the minimum Ruby requirement. Whois 3 no longer supports Ruby 1.8.7 and the minumum Ruby version is now Ruby 1.9.2. With Ruby 2.0 released, it&#8217;s time to move forward.</p>
<h2>Query Handler</h2>
<p>One of the most important features is the introduction of the <strong>query handler</strong>.</p>
<pre class="prettyprint lang-ruby">Whois::Server::Adapters::Base.query_handler.class
# =&gt; Whois::Server::SocketHandler</pre>
<p>The query handler is responsible for the low-level connection between the library and the external WHOIS source. The default query handler, as the class name suggests, is a socket-based handler. It opens a connection to the specified server, writes a query and reads a response that in most cases is the final WHOIS record.</p>
<p>So far so good. But what if you want to use a proxy? Or if you want to be able to use an async socket connection? Before Whois 3 the only way was to monkey patch the library. Today, you simply need to write your own handler and configure the library to use it.</p>
<pre class="prettyprint lang-ruby">class MyHandler
  def call(query, *args)
  # ...
  end
end

Whois::Server::Adapters::Base.query_handler = MyHandler

# This request will use your custom handler
Whois.whois "..."</pre>
<p>Another good case is a Test handler to be used in a test environment. A Test handler would be a simple and effective replacement for all the stubs and mocks across our application spec suite. Also, it will ensure no real socket connection is performed outside our application when our test suite is running.</p>
<h2>Non-Deep querying</h2>
<p>The <a href="https://github.com/weppos/whois/pull/112">support for Non-Deep queries</a> is another long awaited feature. You can now skip deep queries for thin providers passing the `:referral =&gt; false` option.</p>
<pre class="prettyprint lang-ruby">c = Whois::Client.new(referral: false)
c.lookup "google.com"</pre>
<p>The option also works in the command line.</p>
<pre class="prettyprint lang-shell">$ ruby-whois google.com --no-referral</pre>
<h2>Aknowledgements</h2>
<p>Whois 3 was made possible by the contributions of several <a href="https://github.com/weppos/whois/contributors">committers</a> and <a href="https://github.com/weppos/whois/issues">reporters</a>. I would also thank you <a href="dnsimple.com">DNSimple</a> for sponsoring the development of the library.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2010/02/new-in-whois-command-line-improvements/' rel='bookmark' title='New in Whois: command line improvements'>New in Whois: command line improvements</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/09/ruby-whois-preview-answer-and-parser/' rel='bookmark' title='Ruby Whois preview: WHOIS answer and parser'>Ruby Whois preview: WHOIS answer and parser</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/09/ruby-whois-0-8-0/' rel='bookmark' title='Ruby Whois 0.8.0'>Ruby Whois 0.8.0</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/ANGk8eNin2I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2013/03/ruby-whois-3-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2013/03/ruby-whois-3-0/</feedburner:origLink></item>
		<item>
		<title>Understanding the WHOIS protocol</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/vewSad5ucmQ/</link>
		<comments>http://www.simonecarletti.com/blog/2012/03/whois-protocol/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 10:13:27 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Hosting / Domains]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1602</guid>
		<description><![CDATA[An overview of the WHOIS protocol, the de-facto "standard" for querying domain name information.]]></description>
				<content:encoded><![CDATA[<p>The <strong>WHOIS</strong> is a query/response protocol that is widely used to query databases that hold information about internet resources such as domain names and IP address allocations.</p>
<p>Created in the 1980s, WHOIS began as a service used by Internet operators to identify individuals or entities responsible for the operation of a network resource on the Internet. The WHOIS service has since evolved into a tool used for many purposes.</p>
<p>Nowadays the WHOIS protocol is primarily used by registrants and users to query domain registrar databases to obtain domain name information and check domain name availability.<span id="more-1602"></span></p>
<h2>Specification</h2>
<p>The NICNAME/WHOIS protocol was first described in <a href="http://tools.ietf.org/html/rfc812">RFC 812</a> in 1982 by Ken Harrenstien and Vic White of the Network Information Center at SRI International, and subsequently updated 3 years later in <a href="http://tools.ietf.org/html/rfc954">RFC 954</a>.</p>
<p>The <a href="http://tools.ietf.org/html/rfc3912">RFC 3912</a>, published in 2004, is the latest and most significant update to the WHOIS protocol as of today. It renamed the NICNAME/WHOIS to WHOIS and introduced several updates intended to remove the information no longer applicable to the state of the Internet in 2004.</p>
<p>The <strong>RFC 3912 contains the essence of the WHOIS protocol specification</strong>.</p>
<blockquote><p>A WHOIS server listens on TCP port 43 for requests from WHOIS clients. The WHOIS client makes a text request to the WHOIS server, then the WHOIS server replies with text content. All requests are terminated with ASCII CR and then ASCII LF. The response might contain more than one line of text, so the presence of ASCII CR or ASCII LF characters does not indicate the end of the response. The WHOIS server closes its connection as soon as the output is finished. The closed TCP connection is the indication to the client that the response has been received.</p></blockquote>
<p>Whilst the RFC 3912 provides (very little) information about how a WHOIS query should work, it doesn&#8217;t say anything at all about the content of a WHOIS server response. What about the syntax or the encoding?</p>
<p>Also, the WHOIS protocol lacks mechanisms for access control, integrity, and confidentiality.</p>
<p>As a result, <strong>in the years providers designed their own WHOIS server implementation</strong>. The proliferation of customized WHOIS protocols makes almost impossible the creation of an unique, standardized interface to query WHOIS servers and consume WHOIS responses.</p>
<h2>Standardization</h2>
<p>ICANN <a href="http://costarica43.icann.org/node/29689">recently started</a> a project that would eventually end up with the creation of a standardized WHOIS as a replacement for the current WHOIS protocol. This is an extremely ambitious project that unfortunately has a huge chance of failure due to the large adoption of the WHOIS protocol.</p>
<p>Replacing all existing WHOIS servers would requires an incredible effort and this is one of the reasons why similar projects such as <a href="http://projects.arin.net/rwhois/">RWhois</a> and Whois++ have failed in the past.</p>
<p>ICANN is probably the only organization capable of start such kind of reorganization of the WHOIS protocol.</p>
<h2>Current State</h2>
<p>As of today, <strong>the WHOIS protocol is the de-facto &#8220;standard&#8221; for querying domain name information</strong>. The decision to expose or not a public WHOIS interface is completely up to the TLD maintainer.</p>
<p>For instance, the .COM and .DE TLDs provides a public WHOIS interface, the .ES TLD provides a private WHOIS interface while the .VA TLD doesn&#8217;t provide any WHOIS interface. It means there&#8217;s no way to get information about a .VA domain.</p>
<p>The WHOIS protocol is a TCP-based protocol designed to work on the port 43. This makes extremely difficult to perform a WHOIS query from a browser without relying on a server-side third party tool. In fact, client side JavaScript is not able to perform socket requests on port 43.</p>
<p>Because of this, every hosting company provides a custom web-based WHOIS tool to query WHOIS information. The majority of these tools is implemented using a WHOIS API service such as <a href="http://www.robowhois.com/">RoboWhois</a> (*) or <a href="http://www.domaintools.com/">DomainTools</a> or using a WHOIS client. There are WHOIS clients in almost every programming language. <em>(*) Disclaimer: I&#8217;m the author of RoboWhois.</em></p>
<p>Also, it&#8217;s not unusual to find a WHOIS form directly on registry websites. This is the case, for example, of <a href="http://denic.de/">Denic.de</a> for the .DE tld or <a href="http://www.nic.it/">Registro.it</a> for the .IT tld. In several cases, the web-based registry form provides private information normally hidden in the public WHOIS interface, such as contact details.</p>
<p>This is an example of a GoDaddy WHOIS response using the TCP WHOIS interface. Notice the link to the web-based WHOIS interface.</p>
<pre>Please note: the registrant of the domain name is specified
in the "registrant" field.  In most cases, GoDaddy.com, LLC
is not the registrant of domain names listed in this database.

Registrant:
   Simone Carletti

   Registered through: GoDaddy.com, LLC (http://www.godaddy.com)
   Domain Name: WEPPOS.COM

   Domain servers in listed order:
      NS1.DREAMHOST.COM
      NS2.DREAMHOST.COM
      NS3.DREAMHOST.COM

   For complete domain details go to:

http://who.godaddy.com/whoischeck.aspx?Domain=WEPPOS.COM</pre>
<p>There is also a plethora of web-based services that provide WHOIS information, normally mixed with other domain-related and networking details such as IP address, server location and reverse lookup. A large number of these services intentionally re-publishes WHOIS responses as web pages in order to gain visitors from search engines and promote affiliations or products.</p>
<p>For example, here&#8217;s the result page for <a href="https://www.google.com/search?q=whois+expedia.com">whois expedia</a>.</p>
<div class="wp-caption aligncenter" style="width: 764px"><a href="http://f.cl.ly/items/1Q1R1T1W3Q3z2D2F2i1r/simonecarletti-whois-expedia.com.png"><img title="Search results for whois expedia.com" src="http://f.cl.ly/items/1Q1R1T1W3Q3z2D2F2i1r/simonecarletti-whois-expedia.com.png" alt="Search results for whois expedia.com" width="754" /></a><p class="wp-caption-text">Search results for whois expedia.com.</p></div>
<p>In most cases, web-based WHOIS interfaces have been accused of <a href="http://en.wikipedia.org/wiki/Domain_name_front_running">front running domains</a>. The best way to avoid your domain being registered by one of these services is to run WHOIS queries using the socket based WHOIS interface, use the maintainer web-based WHOIS service or make sure the service you want to use contains explicit information about domain name front running in the privacy policy or terms of service.</p>
<h2>Resources</h2>
<p>Despite WHOIS is a very simple protocol, the lack of a well-structured specification transforms it to one of the most complex and unforeseeing protocol to work with. It&#8217;s impossible to cover all WHOIS topics into a single article and I will probably publish more posts in the future.</p>
<p>The following resources can help you to learn more about the WHOIS protocol, query a WHOIS server and consume WHOIS responses.</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Whois">Wikipedia</a> &#8211; the Wikipedia WHOIS article.</li>
<li><a href="http://packages.debian.org/sid/whois">Whois</a> &#8211; the most popular WHOIS commandline client.</li>
<li><a href="http://www.ruby-whois.org/">Ruby Whois</a> &#8211; a WHOIS client and parser in Ruby.</li>
<li><a href="http://www.robowhois.com/">RoboWhois</a> &#8211; a cloud-based web service that provides a RESTful API to access WHOIS records.</li>
</ul>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/09/ruby-whois-preview-answer-and-parser/' rel='bookmark' title='Ruby Whois preview: WHOIS answer and parser'>Ruby Whois preview: WHOIS answer and parser</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/09/ruby-whois-0-8-0/' rel='bookmark' title='Ruby Whois 0.8.0'>Ruby Whois 0.8.0</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/afnic-customizes-whois-responses-for-christmas/' rel='bookmark' title='AFNIC customizes WHOIS responses for Christmas'>AFNIC customizes WHOIS responses for Christmas</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/vewSad5ucmQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2012/03/whois-protocol/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2012/03/whois-protocol/</feedburner:origLink></item>
		<item>
		<title>Heroku and Rails 3.2 asset:precompile error</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/sf9RkGBhJHo/</link>
		<comments>http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 21:34:00 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 3.2]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1575</guid>
		<description><![CDATA[How to configure your Rails 3.2 application to successfully deploy it to Heroku.]]></description>
				<content:encoded><![CDATA[<div class="alert alert-info alert-block target-rails">
<h4>This article targets <strong>Rails &gt;= 3.2</strong></h4>
<p>The article was written as of <strong>Rails 3.2</strong>. The information contained in this page might not apply to different versions.</p>
</div>
<p>I have a very simple Rails 3.1 application, deployed on Heroku. Just <strong>after upgrading it to Rails 3.2, the deploy to Heroku stopped working properly</strong>.</p>
<p>More specifically, the rake <code>asset:precompile</code> task was failing during slug compilation.</p>
<pre>       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----&gt; Writing config/database.yml to read from DATABASE_URL
-----&gt; Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?

       Tasks: TOP =&gt; environment
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:

http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting</pre>
<p>The Heroku <a href="http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting">assets:precompile toubleshooting page</a> contains several explanations, but none of these was my case. In fact, my application was working properly with Rails 3.1.<span id="more-1575"></span></p>
<p>It turns out there are some changes in the Rails 3.2 initialization process that conflicts with Heroku slug compilation. The solution is very simple. All you have to do is to set the Rails 3.2 <code>initialize_on_precompile</code> configuration to false in your <code>application.rb</code> file.</p>
<pre class="prettyprint lang-ruby">config.assets.initialize_on_precompile = false</pre>
<p>This option is new in Rails 3.2 and prevents the Rails environment to be loaded when the <code>assets:precompile</code> task is executed. Because Heroku precompile assets before setting the database configuration, you need to set this configuration to false or you Rails application will try to connect to an unexisting database.</p>
<pre>       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----&gt; Writing config/database.yml to read from DATABASE_URL
-----&gt; Preparing app for Rails asset pipeline
       Running: rake assets:precompile
-----&gt; Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets
...</pre>
<p>This configuration is also documented in the <a href="http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets">Precompiling Assets section</a> of the new Rails 3.2 asset pipeline guide.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/' rel='bookmark' title='Using Sprockets without a Rails/Rack project'>Using Sprockets without a Rails/Rack project</a></li>
<li><a href='http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/' rel='bookmark' title='Configuring Rails 3 to use HTTPS and SSL'>Configuring Rails 3 to use HTTPS and SSL</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/06/capistrano-and-database-yml/' rel='bookmark' title='Capistrano and database.yml'>Capistrano and database.yml</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/sf9RkGBhJHo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/</feedburner:origLink></item>
		<item>
		<title>Eloquent Ruby Book Review</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/F-nT3OWJNMI/</link>
		<comments>http://www.simonecarletti.com/blog/2011/10/eloquent-ruby/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 09:49:25 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[reviews]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1522</guid>
		<description><![CDATA[Eloquent Ruby by Russ Olsen is a book about the Ruby programming language that focuses on Ruby programming style by teaching you how to write your code as a real Rubyist.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.simonecarletti.com/blog/out/amzcom-eloquentruby"><img class="alignleft" title="Book Eloquent Ruby" src="http://img.skitch.com/20120628-e8bh9eij8fgdjk2grgw92u1q6f.png" alt="Book Eloquent Ruby" height="250" /></a> <a href="http://www.simonecarletti.com/blog/out/amzcom-eloquentruby"><em>Eloquent Ruby</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-eloquentruby">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-eloquentruby">UK</a> | <a href="http://www.simonecarletti.com/blog/out/amzit-eloquentruby">IT</a>) is a book about the Ruby programming language that focuses on <strong>Ruby programming style</strong> by teaching you how to write your code as a real Rubyist.</p>
<p>Be prepared, <strong>this is an unconventional Ruby book</strong>. To use author&#8217;s words</p>
<blockquote><p>This is a book about making that final leap, about absorbing the Ruby programming culture, about becoming truly fluent in Ruby.</p></blockquote>
<blockquote><p>A formal understanding of the mechanics of Ruby isn&#8217;t the same as really looking at the programming world through Ruby-colored glasses. You need to absorb the cultural part of Ruby, to see how real Rubyist use the language to solve problems.</p></blockquote>
<p>This is something I have been claiming for the last 5 years. Learning Ruby is not difficult, start thinking in Ruby and becoming a Rubyist is the real challenge.</p>
<p><span id="more-1522"></span></p>
<h2>Structure</h2>
<p>The book is divided into 4 parts. Each part is divided into chapters. The book counts 31 chapters and about 400 pages.</p>
<ol>
<li>The Basics</li>
<li>Classes, Modules, and Blocks</li>
<li>Metaprogramming</li>
<li>Pulling It All Together</li>
</ol>
<p>The first part covers some <strong>basic Ruby features</strong> in a way you normally won&#8217;t read in any other Ruby reference. Ah, if I only had the Symbol chapter available when I started learning Ruby!</p>
<p>The second part covers <strong>Classes, Modules and Blocks</strong> and it explains how to use modules successfully, how to deal with inheritance, equality and operators. This is by far my most favorite section.</p>
<p>The third part is about <strong>Metaprogramming</strong>. Whilst the name of the section is technically correct, it can be misleading. If you are looking for a complete Ruby and Metaprogramming course, check out <a href="http://www.simonecarletti.com/blog/out/amzcom-metaprogrammingruby"><em>Metaprogramming Ruby</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-metaprogrammingruby">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-metaprogrammingruby">UK</a>). This section covers common Ruby metaprogramming topic such as hooks, method_missing (a must read!) and monkey patching.</p>
<p>The fourth part wraps several topics all together and talks about <strong>creating and implementing a DSL</strong> in Ruby.</p>
<p>The book ends with a <strong>rich list of books about Ruby and programming in general</strong>. The list contains amazing Ruby titles like <a href="http://www.simonecarletti.com/blog/out/amzcom-rubybestpractices"><em>Ruby Best Practices</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-rubybestpractices">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-rubybestpractices">UK</a>) or <a href="http://www.simonecarletti.com/blog/out/amzcom-rubyway"><em>The Ruby Way Second Edition</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-rubyway">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-rubyway">UK</a>), as well programming masterpieces like <a href="http://www.simonecarletti.com/blog/out/amzcom-elprogstyle"><em>The Elements of Programming Style</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-elprogstyle">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-elprogstyle">UK</a>). If you are looking for some inspiration about your next reading, you might probably find some there.</p>
<h2>Requirements</h2>
<p>This book assumes that you have a basic knowledge of the Ruby language. You don&#8217;t need to be a Ruby master, but some advanced sections such as Metaprogramming and DSL may require you to stop for a moment and refresh or improve your specific knowledge of Ruby on that topic.</p>
<p>Don&#8217;t expect this book to explain you the basic details of Ruby or its syntax, this is behind the scope of this publication. There are plenty of commented examples, but if you want to learn about a specific Ruby feature make sure you keep a reference like <a href="http://www.simonecarletti.com/blog/out/amzcom-programmingruby"><em>Programming Ruby</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-programmingruby">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-programmingruby">UK</a>) or <a href="http://www.simonecarletti.com/blog/out/amzcom-rubyway"><em>The Ruby Way</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-rubyway">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-rubyway">UK</a>) handy.</p>
<p>Another requirement is that you must be ready to read printed source code: this book is full or Ruby code. At least the 50% of the pages contain code, making this book a valuable practical reference.</p>
<h2>How was it?</h2>
<p>Eloquent Ruby is a very lightweight and pleasant reading. The colloquial tone is friendly and engrossing. The books has plenty of code snippets and it requires only a few days to read it from start to end.</p>
<p>Aside from being an excellent resource to help you thinking Ruby and programming in the Ruby way, this book constantly adopts a practical approach providing tons of examples to read. Every chapter ends with an <em>In the Wild</em> section containing examples extracted from real Ruby libraries, and a <em>Wrapping up</em> section that helps you to fix the concepts in mind.</p>
<p>I appreciated the focus on tests and the RSpec chapter. The most part of the examples are verified by tests, and the tests are also available in the book.</p>
<p>I found the Regular Expression chapter pretty boring and misplaced. In fact, it was the only chapter in the book where the main focus was teaching Regular Expression basics, instead of focusing on using Regular Expressions in the right way.</p>
<p>I would have left the RubyGems section outside the book. There have been several changes in the Gems community in the last years and the chapter appears to be slightly outdated. I would have left this topic outside the book.</p>
<p>As a side note, I would have appreciated a wider usage of Ruby 1.9 over 1.8 in order to discourage the adoption of Ruby 1.8.</p>
<h2>Who should read it?</h2>
<p>If you are a beginner to intermediate level Ruby programmer, this book is a must read that it&#8217;s likely to help you improving your Ruby skill and writing code in the Ruby way.</p>
<p>If you are completely new to Ruby, I don&#8217;t recommend this book as a first reading. You might want to start with a Ruby reference to learn how programming in Ruby, then read Eloquent Ruby to learn how programming in the Ruby way.</p>
<p>If you are a Ruby expert and you have been writing Ruby for the last 5 years, don&#8217;t be too self-confident. I&#8217;m quite sure the book will be able to provide you some valuable advice more than once.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/03/book-review-design-patterns-in-ruby/' rel='bookmark' title='Design Patterns in Ruby Book Review'>Design Patterns in Ruby Book Review</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/03/book-review-learning-jquery/' rel='bookmark' title='Learning jQuery 1.3 Book Review'>Learning jQuery 1.3 Book Review</a></li>
<li><a href='http://www.simonecarletti.com/blog/2011/03/book-review-html-5-up-and-running/' rel='bookmark' title='HTML 5 Up and Running Book Review'>HTML 5 Up and Running Book Review</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/F-nT3OWJNMI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/10/eloquent-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/10/eloquent-ruby/</feedburner:origLink></item>
		<item>
		<title>Using Sprockets without a Rails/Rack project</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/MajF2eLRUXw/</link>
		<comments>http://www.simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 15:28:56 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sprockets]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1485</guid>
		<description><![CDATA[An example of using Sprockets to preprocess and bundle CSS and JavaScript files without a Rails application.]]></description>
				<content:encoded><![CDATA[<p><a href="http://getsprockets.org/">Sprockets</a> is a Ruby library for compiling and serving web assets. It features declarative dependency management for JavaScript and CSS assets and a vert powerful preprocessor pipeline that allows you to write assets in languages like CoffeeScript, Sass or SCSS.</p>
<p>Sprockets is now integrated in Rails 3.1 and is the core library behind the new <strong>Rails 3.1 asset pipeline</strong>. What about if you want to use Sprockets outside a Rails project?</p>
<p>Sprockets exposes a very powerful Rack interface to serve assets over HTTP. <a href="http://www.metabates.com/2011/08/31/using-sprockets-without-rails/">Integrating Sprockets in a Rack application</a>, such as a Sinatra project, turns out to be a very straightforward task.</p>
<p>But in my case, I wanted to use Sprockets preprocessing and bundling feature outside an HTTP application. And it turned out Sprockets is very good at doing this as well.</p>
<p><span id="more-1485"></span>I have a custom shared template I created several months ago called docss. I use this for several projects such as <a href="http://www.ruby-whois.org/">Ruby Whois</a> and <a href="http://www.robowhois.com/">RoboWhois</a>. The template is composed of several CSS files. I have a Ruby <code>rake</code> script that merges these files and packages them into a single asset, then compress it and publish the result to <a href="http://aws.amazon.com/cloudfront/">Amazon CloudFront</a>.</p>
<p>Instead of processing and merging the files using file system tasks I&#8217;m now delegating this task to Sprockets. The project directory structure looks like this</p>
<pre class="prettyprint lang-bash">.
├── Gemfile
├── Gemfile.lock
├── Rakefile
├── build
│   ├── javascripts
│   │   └── all.js
│   └── stylesheets
│       ├── 960.css
│       ├── alignments.css
│       ├── all.css
│       ├── reset.css
│       ├── screen.css
│       └── syntax.css
├── lib
│   └── yuicompressor-2.4.2.jar
└── src
    ├── javascripts
    │   └── all.js
    └── stylesheets
        ├── 960.css
        ├── alignments.css
        ├── all.css
        ├── reset.css
        ├── screen.css.scss
        └── syntax.css</pre>
<p>And here&#8217;s my <code>compile</code> task</p>
<pre class="prettyprint lang-ruby">require 'rubygems'
require 'bundler'
require 'pathname'
require 'logger'
require 'fileutils'

Bundler.require

ROOT        = Pathname(File.dirname(__FILE__))
LOGGER      = Logger.new(STDOUT)
BUNDLES     = %w( all.css all.js )
BUILD_DIR   = ROOT.join("build")
SOURCE_DIR  = ROOT.join("src")

task :compile do
  sprockets = Sprockets::Environment.new(ROOT) do |env|
    env.logger = LOGGER
  end

  sprockets.append_path(SOURCE_DIR.join('javascripts').to_s)
  sprockets.append_path(SOURCE_DIR.join('stylesheets').to_s)

  BUNDLES.each do |bundle|
    assets = sprockets.find_asset(bundle)
    prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
    FileUtils.mkpath BUILD_DIR.join(prefix)

    assets.write_to(BUILD_DIR.join(prefix, basename))
    assets.to_a.each do |asset|
      # strip filename.css.foo.bar.css multiple extensions
      realname = asset.pathname.basename.to_s.split(".")[0..1].join(".")
      asset.write_to(BUILD_DIR.join(prefix, realname))
    end
  end
end</pre>
<p>First I create a new <code>Sprockets::Environment</code> instance passing some configurations, such as a custom logger.</p>
<pre class="prettyprint lang-ruby">sprockets = Sprockets::Environment.new(ROOT) do |env|
  env.logger = LOGGER
end</pre>
<p>Then I append the asset paths.</p>
<pre class="prettyprint lang-ruby">sprockets.append_path(SOURCE_DIR.join('javascripts').to_s)
sprockets.append_path(SOURCE_DIR.join('stylesheets').to_s)</pre>
<p>Finally, I process and package the assets to the build directory.</p>
<pre class="prettyprint lang-ruby">assets.write_to(BUILD_DIR.join(prefix, basename))</pre>
<p>Because sometimes I need to reference a single CSS file (e.g. <code>alignments.css</code>) instead of the entire bundle, I also build a standalone package for each CSS source. You might not want to do that.</p>
<pre class="prettyprint lang-ruby">assets.to_a.each do |asset|
  # strip filename.css.foo.bar.css multiple extensions
  realname = asset.pathname.basename.to_s.split(".")[0..1].join(".")
  asset.write_to(BUILD_DIR.join(prefix, realname))
end</pre>
<p>Please keep in mind that if you want to use processors you must include the corresponding libraries. For example, if you want to support <code>SASS</code> processor you need to add the <code>sass</code> gem.</p>
<p>Here&#8217;s my <code>Gemfile</code>.</p>
<pre class="prettyprint lang-ruby">source "http://rubygems.org"

gem 'sass'
gem 'sprockets'</pre>
<p>That&#8217;s all.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/' rel='bookmark' title='Heroku and Rails 3.2 asset:precompile error'>Heroku and Rails 3.2 asset:precompile error</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/07/the-way-to-rails-3/' rel='bookmark' title='The Road to Rails 3: make your Rails 2.3 project more Rails 3 oriented'>The Road to Rails 3: make your Rails 2.3 project more Rails 3 oriented</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/' rel='bookmark' title='Capistrano: Executing a command as root without using sudo'>Capistrano: Executing a command as root without using sudo</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/MajF2eLRUXw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/</feedburner:origLink></item>
		<item>
		<title>the Rubyist</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/fDLusjkJ6_Y/</link>
		<comments>http://www.simonecarletti.com/blog/2011/09/the-rubyist/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 14:42:39 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1479</guid>
		<description><![CDATA[the Rubyist is a collection of conventions and standards for Ruby programmers.]]></description>
				<content:encoded><![CDATA[<p>Several years ago I started keeping track of Ruby coding conventions that my team and I were using in-house. The purpose was to document the most important guidelines we employ in order to keep our libraries and source code consistent, regardless the maintainer.</p>
<p>The result of this effort is <a title="the Rubyist" href="http://rubyist.info/">the Rubyist</a>, a collection of conventions and standards for Ruby programmers. The project is now <a href="http://github.com/weppos/rubyist">open source</a>, you can fork it and contribute.</p>
<div class="wp-caption aligncenter" style="width: 510px"><img title="the Rubyist Homepage" src="http://f.cl.ly/items/211F0S1e1H3A3c0q3235/simonecarletti-rubyist.png" alt="the Rubyist Homepage" width="500" /><p class="wp-caption-text">the Rubyist Homepage</p></div>
<p><span id="more-1479"></span>When I first started learning Ruby, several years ago, there was a very nice project called <strong>RubyGarden</strong>. This project was a real treasure for those learning Ruby because it was full of resources and information about the Ruby world. If you have been developing in Ruby for a long time, I&#8217;m sure you&#8217;ll remember it.</p>
<p>But most of all, the RubyGarden has been extremely helpful to me (and many others) in learning about Ruby conventions and the most notable Ruby best practices. One page in particular, the <strong>RubyStyleGuide</strong>, was a collection of Ruby coding standard and naming conventions that every Ruby developer ought to have been familiar with.</p>
<div class="wp-caption aligncenter" style="width: 510px"><img title="RubyGarden Ruby Style Guide" src="http://f.cl.ly/items/390z1t2i3c0P2U2g2305/simonecarletti-rubygarden.png" alt="RubyGarden Ruby Style Guide" width="500" /><p class="wp-caption-text">RubyGarden Ruby Style Guide</p></div>
<p>A lot has changed since then.</p>
<p>The RubyGarden project was shut down a few years ago. As far I remember, the wiki was invaded by spam and the <code>www.rubygarden.org</code> domain has now been hijacked.</p>
<p>The Ruby language has evolved. Ruby 1.8 and Ruby 1.9 have introduced several new syntax changes and conventions. Moreover, the adoption of the Ruby programming language has increased over the years and several new common programming patterns have arisen.</p>
<p><a href="https://github.com/">GitHub</a> was born. If you are in the habit of <a href="http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-reading-source-code/">read the source code</a>, GitHub is like a chocolate factory for a child. You can find an countless number of Ruby projects, filter them, sort them and read the source code to learn from it. Just pick some random accounts owned by notable Ruby developers, explore their programming habits and learn new exciting best practices and patterns.</p>
<p>Even with these newly available resources, there are many times when an quick reference can come in most handy.</p>
<p>Whether you are a Ruby master or a newbie, I hope you&#8217;ll find <a href="rubyist.info">the Rubyist</a> to be a source of inspiration.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2011/10/eloquent-ruby/' rel='bookmark' title='Eloquent Ruby Book Review'>Eloquent Ruby Book Review</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/09/rails-3-beware-the-tap-pattern/' rel='bookmark' title='Upgrading to Rails 3: Beware of the Object#tap pattern'>Upgrading to Rails 3: Beware of the Object#tap pattern</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/01/search-simonecarletti-com-from-google-chrome/' rel='bookmark' title='Search SimoneCarletti.com from Google Chrome address bar'>Search SimoneCarletti.com from Google Chrome address bar</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/fDLusjkJ6_Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/09/the-rubyist/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/09/the-rubyist/</feedburner:origLink></item>
		<item>
		<title>Configuring Rails 3 to use HTTPS and SSL</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/QxOYE7xiN6E/</link>
		<comments>http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/#comments</comments>
		<pubDate>Thu, 05 May 2011 10:45:53 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 3]]></category>
		<category><![CDATA[rails 3.1]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1447</guid>
		<description><![CDATA[Ways to force your Rails application to use SSL and the HTTPS protocol.]]></description>
				<content:encoded><![CDATA[<div class="alert alert-info alert-block target-rails">
<h4>This article targets <strong>Rails 3</strong> and <strong>Rails 3.1</strong>.</h4>
<p>The information contained in this page might not apply to different versions.</p>
</div>
<p>There are several ways to force your Rails application to use SSL and the HTTPS protocol.<span id="more-1447"></span></p>
<h2>Rails &gt;= 3.1</h2>
<p>If you are using Rails 3.1 (currently available in beta1) or greater, <a href="https://github.com/rails/rails/commit/2c0c4d754e34b13379dfc53121a970c25fab5dae">this commit</a> makes it incredibly easy to switch from HTTP/HTTPS and vice-versa.</p>
<p>Simply use <code>config.force_ssl = true</code> in your environment configuration.</p>
<pre class="prettyprint lang-ruby"># config/application.rb
module MyApp
  class Application &lt; Rails::Application
    config.force_ssl = true
  end
end</pre>
<p>You can also selectively enable https depending on the current Rails environment. For example, you might want to keep HTTPS turned off on development, and enable it on staging/production.</p>
<pre class="prettyprint lang-ruby"># config/application.rb
module MyApp
  class Application &lt; Rails::Application
    config.force_ssl = false
  end
end

# config/environments/production.rb
MyApp::Application.configure do
  config.force_ssl = true
end</pre>
<p>Behind the scenes, Rails adds the awesome <a href="https://rubygems.org/gems/rack-ssl">Rack::SSL Rack middleware</a> to your application middleware stack. <code>Rack::SSL</code> automatically filters the request, redirects not-HTTPS requests to the corresponding HTTPS path and applies some additional improvements to make sure your HTTPS request is secure.</p>
<h2>Rails &lt; 3.1</h2>
<p>If you&#8217;re not using Rails 3.1 don&#8217;t worry. Enabling HTTPS is as easy as adding the following line to your environment configuration.</p>
<pre class="prettyprint lang-ruby">config.middleware.insert_before ActionDispatch::Static, "Rack::SSL"</pre>
<p>Note that I&#8217;m passing <code>Rack::SSL</code> as string to delegate the loading of the class at the end of the Rails application initialization. Also note the middleware must be inserted in a specific position in the stack, at least before <code>ActionDispatch::Static</code> and <code>ActionDispatch::Cookies</code>.</p>
<p>Don&#8217;t forget to define <code>Rack::SSL</code> dependency in your <code>Gemfile</code>.</p>
<pre class="prettyprint lang-ruby"># Gemfile
gem 'rack-ssl', :require =&gt; 'rack/ssl'</pre>
<h2>Enabling HTTPS and HTTP in parallel</h2>
<p>Transitioning an HTTP-based application to HTTPS might not be as easy as you think, especially if your application embeds assets from third-party hosts.</p>
<p>There are cases where you want to make your application available using both HTTP and HTTPS. For instance, we adopted this strategy in <a title="The easier way to track your domains" href="https://www.robodomain.com/">RoboDomain</a> for a while when we <a title="Going SSL - RoboBlog" href="http://blog.robodomain.com/post/3581778301/going-ssl">moved the application to HTTPS</a>.</p>
<p><code>Rack::SSL</code> has a very interesting and undocumented feature. You can pass an <code>:exclude</code> option to determine when to enable/disable the use of HTTPS.</p>
<p>The following code enables Rack::SSL and all its filters only in case the request comes from a HTTPS connection.</p>
<pre class="prettyprint lang-ruby">config.middleware.insert_before ActionDispatch::Static, Rack::SSL, :exclude =&gt; proc { |env| env['HTTPS'] != 'on' }</pre>
<p>Both the following URLs will continue to work, but the first one will trigger the <code>Rack::SSL</code> filters.</p>
<pre>https://example.com

http://example.com</pre>
<p>This solution also works very well for cloud providers like <strong>Heroku</strong> and completely replaces home-made solutions like the one I posted in <a title="Force SSL using ssl_requirement in Rails app - Stack Overflow" href="http://stackoverflow.com/questions/3861772/force-ssl-using-ssl-requirement-in-rails-app">this StackOverflow answer</a> months ago, also featured <a href="http://clearcove.ca/blog/2010/11/how-to-secure-a-rails-app-on-heroku-with-ssl-firesheep/">here</a> and <a href="http://blog.dynamic50.com/2011/02/15/ssl-on-wildcard-domains-on-heroku-using-godaddy/">here</a>.</p>
<p>If you want to <strong>use SSL on Heroku and redirect the HTTP traffic to HTTPS</strong>, my suggestion is to go with <code>Rack::SSL</code>.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2011/04/understanding-ruby-and-rails-lazy-load-hooks/' rel='bookmark' title='Understanding Ruby and Rails: Lazy load hooks'>Understanding Ruby and Rails: Lazy load hooks</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/07/the-way-to-rails-3/' rel='bookmark' title='The Road to Rails 3: make your Rails 2.3 project more Rails 3 oriented'>The Road to Rails 3: make your Rails 2.3 project more Rails 3 oriented</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/08/rails-3-you-are-using-the-old-router-dsl/' rel='bookmark' title='Upgrading to Rails 3: You are using the old router DSL which will be removed in Rails 3.1'>Upgrading to Rails 3: You are using the old router DSL which will be removed in Rails 3.1</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/QxOYE7xiN6E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/</feedburner:origLink></item>
		<item>
		<title>Google changes the maximum number of users for Google Apps</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/6v2TWzcjoPY/</link>
		<comments>http://www.simonecarletti.com/blog/2011/04/google-changes-the-maximum-number-of-users-for-google-apps/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 07:31:13 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Hosting / Domains]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google apps]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1442</guid>
		<description><![CDATA[Starting from 10 May 2011, the new maximum number of users for a Google Apps for free account will be set to 10.]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-1443" title="Google Apps Circle" src="http://www.simonecarletti.com/blog/wp-content/uploads/2011/04/google-apps-circle-136x150.png" alt="" width="136" height="150" />I just received an email from Google about upcoming changes to the maximum number of users for <a title="Google Apps" href="http://google.com/a">Google Apps</a>. When Google Apps was released, Google allowed all accounts to create up to 500 users. <a title="Official Google Enterprise Blog: Serving businesses better with Google Apps" href="http://googleenterprise.blogspot.com/2009/01/serving-businesses-better-with-google.html">The limit was changed in 2009</a> for free accounts and reduced to 50 users.</p>
<p>Today, Google is changing this limit again to 10 users. Here&#8217;s the content of the email.</p>
<blockquote><p>Hello,</p>
<p>We recently announced upcoming changes to the maximum number of users for Google Apps. We want to let you know that, as a current customer, the changes will not affect you.</p>
<p>As of May 10, any organization that signs up for a new account will be required to use the paid Google Apps for Business product in order to create more than 10 users. We honor our commitment to all existing customers and will allow you to add more than 10 users to your account for DOMAIN at no additional charge, based on the limit in place when you joined us.</p>
<p>Sincerely,</p>
<p>The Google Apps Team</p></blockquote>
<p>Starting from 10 May 2011, the new maximum number of users for a <em>Google Apps for free</em> account will be set to 10.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/01/google-serp-full-of-this-site-may-harm-your-computer-warnings/' rel='bookmark' title='Google SERP full of &#8220;This site may harm your computer&#8221; warnings'>Google SERP full of &#8220;This site may harm your computer&#8221; warnings</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/google-site-performance-tool-gzip/' rel='bookmark' title='Google Site performance tool says Google is not serving Gzipped resources'>Google Site performance tool says Google is not serving Gzipped resources</a></li>
<li><a href='http://www.simonecarletti.com/blog/2005/12/google-personalized-homepage-rmail-module/' rel='bookmark' title='Google Personalized Homepage RMail module'>Google Personalized Homepage RMail module</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/6v2TWzcjoPY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/04/google-changes-the-maximum-number-of-users-for-google-apps/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/04/google-changes-the-maximum-number-of-users-for-google-apps/</feedburner:origLink></item>
		<item>
		<title>RSpec Rails doesn’t render Rails views by default</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/Ue9agQPrgQQ/</link>
		<comments>http://www.simonecarletti.com/blog/2011/04/rspec-rails-doesnt-render-rails-views-by-default/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 07:54:23 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1433</guid>
		<description><![CDATA[RSpec (actually the RSpec Rails gem) doesn't render the content of the action by default, like the common Rails functional tests do.]]></description>
				<content:encoded><![CDATA[<p>If you are using <strong>RSpec</strong> and <strong>RSpec Rails</strong> to test your Rails application, I strongly encourage you to keep reading this post because there&#8217;s a gotcha in the default configuration you might not expect, especially if you ever used the default Rails test framework before.</p>
<p>A couple of days ago I was notified about a but in a Rails application. The application crashed when trying to create a new record.</p>
<p>I changed the <code>new</code> action the day before, but I was sure all the tests passed and the action was covered with a pretty reasonable RSpec test suite. Moreover, the action method was one of the most simplest methods I have ever written.</p>
<pre class="prettyprint lang-ruby">def new
  @record = Model.new
end</pre>
<p>I run the test suite, all green. I executed the page in the browser, it crashed.</p>
<div id="attachment_1434" class="wp-caption aligncenter" style="width: 384px"><img class="size-full wp-image-1434" title="WTF Monkey" src="http://www.simonecarletti.com/blog/wp-content/uploads/2011/04/wtf.jpg" alt="" width="374" height="300" /><p class="wp-caption-text">My face when I discovered all tests passed but the action kept crashing.</p></div>
<p>After several minutes of debugging I discovered the culprit: RSpec (actually the RSpec Rails gem) doesn&#8217;t render the content of the action by default, like the common Rails functional tests do. In fact, <code>@response.body</code> always resulted in an empty string.<span id="more-1433"></span></p>
<p>The view contained a statement like the following</p>
<pre class="prettyprint lang-ruby">&lt;%= f.collection_select Model.all, :id, :name %&gt;</pre>
<p>that was misspelled and crashed when the template was rendered. But because RSpec doesn&#8217;t render the Rails views, the view was not covered by the tests at all.</p>
<p>The solution is simple and is called <a href="http://relishapp.com/rspec/rspec-rails/v/2-5/dir/controller-specs/render-views">render_views</a>.</p>
<p>To tell a controller to render the content of the view, simply call <code>render_views</code>.</p>
<pre class="prettyprint lang-ruby">require "spec_helper"

describe RecordsController do
  render_views

  describe "GET index" do
    # ...
  end
end</pre>
<p>You can also enable <code>render_views</code> globally, in your <code>spec_helper.rb</code> file.</p>
<pre class="prettyprint lang-ruby">RSpec.configure do |config|
  config.render_views
end</pre>
<p>The reason behind this choice is because RSpec Rails actually provides a special RSpec group called &#8220;view specs&#8221;.</p>
<pre class="prettyprint lang-ruby">describe "events/index.html.erb" do
  it "renders _event partial for each event" do
    assign(:events, [stub_model(Event), stub_model(Event)])
    render
    view.should render_template(:partial =&gt; "_event", :count =&gt; 2)
  end
end</pre>
<p>According to the documentation, this is the right way to test Rails templates in RSpec. Honestly, I never really liked this feature and I tend to keep using controller specs — the RSpec equivalent of functional tests — (or alternative test tools) to test the views.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2010/12/get-the-currently-described-class-in-rspec/' rel='bookmark' title='Get the currently described class in RSpec'>Get the currently described class in RSpec</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/08/user-profile-permalinks-with-ruby-on-rails-and-authlogic/' rel='bookmark' title='User profile permalinks with Ruby on Rails (and Authlogic)'>User profile permalinks with Ruby on Rails (and Authlogic)</a></li>
<li><a href='http://www.simonecarletti.com/blog/2011/02/new-in-whois-gem-testers/' rel='bookmark' title='New in Whois: Gem Testers'>New in Whois: Gem Testers</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/Ue9agQPrgQQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/04/rspec-rails-doesnt-render-rails-views-by-default/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/04/rspec-rails-doesnt-render-rails-views-by-default/</feedburner:origLink></item>
		<item>
		<title>Understanding Ruby and Rails: Lazy load hooks</title>
		<link>http://feeds.simonecarletti.com/~r/simonecarletti/en/~3/HpSNxcMLmp8/</link>
		<comments>http://www.simonecarletti.com/blog/2011/04/understanding-ruby-and-rails-lazy-load-hooks/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 08:22:54 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[activesupport]]></category>
		<category><![CDATA[lazy-load]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1426</guid>
		<description><![CDATA[With Rails 3 you can now register specific hooks to be lazy-executed when the corresponding library is loaded.]]></description>
				<content:encoded><![CDATA[<div class="alert alert-info alert-block target-rails">
<p>This article targets <strong>Rails 3</strong>. The information contained in this page might not apply to different versions.</p>
</div>
<p><em>This is article is part of my series Understanding Ruby and Rails. Please see the <a href="http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-reading-source-code/">table of contents</a> for the series to view the list of all posts.</em></p>
<p>A small-but-interesting feature introduced in <strong>Rails 3</strong> is the built-in support for <strong>lazy loading</strong>.</p>
<p>Lazy loading is a very common <strong>design pattern</strong>. The concept is to defer initialization of an object until the point at which it is needed. This design pattern decreases the time required by an application to boot by distributing the computation cost during the execution. Also, if a specific feature is never used, the computation won&#8217;t be executed at all.</p>
<p>With Rails 3 you can now register specific hooks to be lazy-executed when the corresponding library is loaded.</p>
<pre class="prettyprint lang-ruby">class ApplicationController &lt; ActionController::Base

  initializer "active_record.include_plugins" do
    ActiveSupport.on_load(:active_record) do
      include MyApp::ActivePlugins
    end
  end

end</pre>
<p>In this case we register the block to be executed when the <code>ActiveRecord</code> library is loaded. If you read the <a href="https://github.com/rails/rails/blob/v3.0.6/activerecord/lib/active_record/base.rb">ActiveRecord::Base source code</a>, the very last line is a call to</p>
<pre class="prettyprint lang-ruby">ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)</pre>
<p>This line of code executes all the hooks previously registered for <code>ActiveRecord</code>.<span id="more-1426"></span></p>
<h2>lazy-load hooks in the wild</h2>
<p>Perhaps one of the most frequent usage of the lazy-load hooks is in Rails plugins.</p>
<p>For example, if your plugin needs to register some helpers, you can write a hook to include the helpers in <code>ActionView</code> only when <code>ActionView</code> is loaded. If the environment is loaded from a rake task (which doesn&#8217;t necessary need <code>ActionView</code>), then your plugin hook won&#8217;t be executed and the Rails application will boot faster.</p>
<p>Here&#8217;s an example from the <code>will_paginate</code> gem.</p>
<pre class="prettyprint lang-ruby">require 'will_paginate'
require 'will_paginate/collection'

module WillPaginate
  class Railtie &lt; Rails::Railtie
    initializer "will_paginate.active_record" do |app|
      ActiveSupport.on_load :active_record do
        require 'will_paginate/finders/active_record'
        WillPaginate::Finders::ActiveRecord.enable!
      end
    end

    initializer "will_paginate.action_dispatch" do |app|
      ActiveSupport.on_load :action_controller do
        ActionDispatch::ShowExceptions.rescue_responses['WillPaginate::InvalidPage'] = :not_found
      end
    end

    initializer "will_paginate.action_view" do |app|
      ActiveSupport.on_load :action_view do
        require 'will_paginate/view_helpers/action_view'
        include WillPaginate::ViewHelpers::ActionView
      end
    end
  end
end</pre>
<h2>Using lazy load in your libraries</h2>
<p>So far, we only discussed about using lazy-loading to hook Rails core library. Because lazy-loading is an <code>ActiveSupport</code> feature, you can use it in your Rails applications but also in your own Ruby classes.</p>
<p>First, make sure to add a call to <code>ActiveSupport.run_load_hooks</code> at the end of your Ruby class.</p>
<pre class="prettyprint lang-ruby">class HttpClient
  # ...

  ActiveSupport.run_load_hooks(:http_client, self)
end</pre>
<p>Now you can register on_load hooks everywhere passing the name of the library used in <code>run_load_hooks</code>.</p>
<pre class="prettyprint lang-ruby">class Request
  # ...

  ActiveSupport.on_load :http_client do
    # do something
  end
end

class Response
  # ...

  ActiveSupport.on_load :http_client do
    # do something
  end
end</pre>
<h2>Hook context</h2>
<p>The <code>run_load_hooks</code> method takes a second parameter representing the context within the hook will be executed. It&#8217;s a common pattern to pass the class/instance the hooks refer to.</p>
<p>For instance, the <code>ActiveRecord</code> library mentioned at the beginning of the article passes <code>self</code>. In that context, <code>self</code> references the <code>ActiveRecord::Base</code> class.</p>
<p>This is useful because, if you want to include some custom methods into ActiveRecord, you can use the following block</p>
<pre class="prettyprint lang-ruby">ActiveSupport.on_load :active_record do
  include MyPlugin::Extensions
end</pre>
<p>instead of</p>
<pre class="prettyprint lang-ruby">ActiveSupport.on_load :active_record do
  ActiveRecord::Base.send :include, MyPlugin::Extensions
end</pre>
<p>There&#8217;s also an other interesting use case for this feature. If you want to perform some kind of lazy-initialization when an instance of a class is created, just pass the instance itself.</p>
<pre class="prettyprint lang-ruby">class Color
  def initialize(name)
    @name = name

    ActiveSupport.run_load_hooks(:instance_of_color, self)
  end
end

ActiveSupport.on_load :instance_of_color do
  puts "The color is #{@name}"
end

Color.new("yellow")
# =&gt; "The color is yellow"</pre>
<h2>Source Code</h2>
<p>The source code of the lazy-loading feature is available in the <a href="https://github.com/rails/rails/blob/v3.0.6/activesupport/lib/active_support/lazy_load_hooks.rb">lazy_load_hooks.rb</a> file.</p>
<div class='yarpp-related-rss'>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/12/inside-ruby-on-rails-rescuable-and-rescue_from/' rel='bookmark' title='Understanding Ruby and Rails: Rescuable and rescue_from'>Understanding Ruby and Rails: Rescuable and rescue_from</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-reading-source-code/' rel='bookmark' title='Understanding Ruby and Rails: Reading Source Code'>Understanding Ruby and Rails: Reading Source Code</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/' rel='bookmark' title='Understanding Ruby and Rails: extract_options! from Arrays'>Understanding Ruby and Rails: extract_options! from Arrays</a></li>
</ol></p>
</div>
<img src="http://feeds.feedburner.com/~r/simonecarletti/en/~4/HpSNxcMLmp8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2011/04/understanding-ruby-and-rails-lazy-load-hooks/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.simonecarletti.com/blog/2011/04/understanding-ruby-and-rails-lazy-load-hooks/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.386 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-14 23:17:20 -->
