<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <title>Astrails - Home</title>
  <id>tag:blog.astrails.com,2010:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  
  <link href="http://blog.astrails.com/" rel="alternate" type="text/html" />
  <updated>2010-07-05T15:44:06Z</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Astrails" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="astrails" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2010-07-05:391</id>
    <published>2010-07-05T15:43:00Z</published>
    <updated>2010-07-05T15:44:06Z</updated>
    <category term="Rails" />
    <category term="Ruby" />
    <category term="mock" />
    <category term="rr" />
    <category term="specs" />
    <category term="tdd" />
    <category term="test" />
    <category term="testing" />
    <link href="http://blog.astrails.com/2010/7/5/how-to-mock-backticks-operator-in-your-test-specs-using-rr" rel="alternate" type="text/html" />
    <title>how to mock `backticks operator` in your test specs using RR</title>
<content type="html">
            &lt;p&gt;I was working on tests for &lt;a href="http://astrails.com/opensource/server-blender"&gt;blender&lt;/a&gt; when I came upon a need to mock or stub a back-tick operator e.g. &lt;code&gt;`shell command`&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Apparently this is just a shortcut for calling &lt;code&gt;Kernel&lt;/code&gt; method &lt;code&gt;:`&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So the mocking should probably be easier with Rspec mocks or mocha. something like that (didn’t test see below):&lt;/p&gt;

&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;@obj.should_receive(:`, "shell command").and_return("....")&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But the problem was that I’m using &lt;a href="http://github.com/btakita/rr"&gt;RR&lt;/a&gt;. And RR uses a much more succinct and easy to use syntax but in this particular case it was a problem. Consider this:&lt;/p&gt;

&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;# This doesn't work. it stubs the :send, not the :`
stub(@obj).send(:`, "shell command") { "...." }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;RR has an instance_eval syntax, but with it I don’t know how to pass a block to the back-ticks call:&lt;/p&gt;

&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;stub(@obj) do
  `shell command` { "...." } # invalid syntax here ;). 
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So after some digging inside RR’s sources I got the following working:&lt;/p&gt;

&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;stub(@obj).
  __double_definition_create__.
    call(:`, "shell command") { "...." }
&lt;/code&gt;&lt;/pre&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/fHG4dJ8qCp4" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>michael</name>
    </author>
    <id>tag:blog.astrails.com,2010-06-16:381</id>
    <published>2010-06-16T19:06:00Z</published>
    <updated>2010-06-16T19:07:48Z</updated>
    <category term="Astrails" />
    <category term="nosql" />
    <category term="Rails" />
    <category term="Ruby" />
    <category term="speaking" />
    <link href="http://blog.astrails.com/2010/6/16/open-2010-conference" rel="alternate" type="text/html" />
    <title>Open 2010 Conference</title>
<summary type="html">&lt;p&gt;The &lt;a href="http://openisrael.co.il"&gt;OPEN 2010 conference&lt;/a&gt; was very well organized and had many interesting talks.&lt;/p&gt;

&lt;p&gt;The side of low level, infrastructure things was presented by people from Red Hat, VMWare and IBM. The buzz words “SaaS”, “PaaS” and the likes were all over the place together with recent hot topic of virtualization.&lt;/p&gt;

&lt;p&gt;On the application level there were interesting presentations about Django, PostgreSQL. And of course our own presentations on Ruby, Rails, NoSQL along with a longer, 2 hours “Introduction to Ruby” workshop.&lt;/p&gt;

&lt;p&gt;The food was great too. That’s important.&lt;/p&gt;

&lt;p&gt;We uploaded our slides with english transcription for some of them on the &lt;a href="http://astrails.com/speaking"&gt;“we speak” page&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/2Dp0dDziL7w" height="1" width="1"/&gt;</summary>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2010-06-09:371</id>
    <published>2010-06-09T08:41:00Z</published>
    <updated>2010-06-16T19:04:33Z</updated>
    <category term="Astrails" />
    <category term="Rails" />
    <category term="Ruby" />
    <category term="speaking" />
    <category term="astrails" />
    <category term="nosql" />
    <category term="open source" />
    <category term="open2010" />
    <category term="rails" />
    <link href="http://blog.astrails.com/2010/6/9/open-2010-tomorrow-and-we-are-there-big-time" rel="alternate" type="text/html" />
    <title>open 2010 tomorrow and we are there big time</title>
<content type="html">
            &lt;p&gt;We are giving 4 out of 20 sessions at &lt;a href="http://www.openisrael.co.il/"&gt;Open 2010&lt;/a&gt;, an Israeli open source conference.&lt;/p&gt;

&lt;p&gt;Michael is giving the last keynote and me and Boris will be opening 2 of the 3 tracks: open startup and open enterprise.&lt;/p&gt;

&lt;p&gt;I’m going to talk about “NoSQL, when, why, and how” and Boris is giving an introduction to Rails, web development that doesn’t hurt.&lt;/p&gt;

&lt;p&gt;After the tracks we will also have a long 2 hour  Ruby and Rails workshop.&lt;/p&gt;

&lt;p&gt;See you there ;)&lt;/p&gt;

&lt;p&gt;P.S. btw, Astrails is sponsoring this event together with a couple of smaller 
companies like IBM, Red Hat and VMWare :) &lt;/p&gt;

&lt;p&gt;P.P.S. Big thanks goes to Raphael Fogel and People&amp;amp;Computers for organizing the whole thing. &lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/5KLujGeV0Rc" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2010-05-21:351</id>
    <published>2010-05-21T02:46:00Z</published>
    <updated>2010-05-21T02:46:13Z</updated>
    <category term="osx" />
    <category term="Rails" />
    <category term="Ruby" />
    <category term="mysql" />
    <category term="osx" />
    <category term="rails" />
    <category term="ruby" />
    <category term="rubygems" />
    <category term="snow leopard" />
    <link href="http://blog.astrails.com/2010/5/21/installing-mysql-gem-on-snow-leopard" rel="alternate" type="text/html" />
    <title>installing mysql gem on Snow Leopard</title>
<content type="html">
            &lt;p&gt;I just recently reinstalled my MacBook Pro, this time with Snow Leopard.
So I’m again going through various installation problems I already forgot about from few years back when I installed Leopard.&lt;/p&gt;

&lt;p&gt;Anyway, just had to hunt down a problem with mysql gem installation on Snow Leopard.&lt;/p&gt;

&lt;p&gt;Apparently if you just do ‘gem install mysql’ it seems to install fine, but doesn’t work.&lt;/p&gt;

&lt;p&gt;You get “uninitialized constant MysqlCompat::MysqlRes” error when trying to run rails.&lt;/p&gt;

&lt;p&gt;The solution is to pass it some arguments for installation:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Oh, and of course install 64bit mysql version before that. I usually just download the binaries from mysql.com.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/S0auHOI7Xgk" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2010-05-20:341</id>
    <published>2010-05-20T13:37:00Z</published>
    <updated>2010-05-20T13:38:54Z</updated>
    <category term="Ruby" />
    <category term="lisp" />
    <category term="ruby" />
    <link href="http://blog.astrails.com/2010/5/20/ruby-is-better-then-lisp-sometimes" rel="alternate" type="text/html" />
    <title>Ruby is Better then Lisp (sometimes)</title>
<content type="html">
            &lt;p&gt;A few days ago I gave a presentation about Ruby for &lt;a href="http://groups.google.com/group/sayeret-lambda"&gt;Sayeret Lambda&lt;/a&gt; discussion group.&lt;/p&gt;


	&lt;p&gt;The title was “Ruby is an acceptable lisp” but the message is better served by “Ruby is Better then Lisp … sometimes” :)&lt;/p&gt;


The presentation slides are now online:
	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://astrails.com/presentations/ruby-is-an-acceptable-lisp.pdf"&gt;ruby-is-an-acceptable-lisp.pdf&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://astrails.com/presentations/ruby-is-an-acceptable-lisp.html"&gt;online html/jpeg version&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The html version is just an export from Keynote so nothing fancy, it only knows how to move forward :)
Some slides are bigger, so don’t click again if it seems that its stuck (you will have to refresh to go back), just wait a little.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/6RLKuy3WMDw" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>michael</name>
    </author>
    <id>tag:blog.astrails.com,2010-04-26:331</id>
    <published>2010-04-26T16:47:00Z</published>
    <updated>2010-04-26T16:51:54Z</updated>
    <category term="Astrails" />
    <category term="Markupslicer" />
    <category term="Rails" />
    <category term="css" />
    <category term="dev" />
    <category term="development" />
    <category term="erb" />
    <category term="free" />
    <category term="haml" />
    <category term="html" />
    <category term="layout" />
    <category term="markup" />
    <category term="online" />
    <category term="rails" />
    <category term="ruby" />
    <category term="slice" />
    <category term="template" />
    <category term="web" />
    <link href="http://blog.astrails.com/2010/4/26/markupslicer-our-new-side-project" rel="alternate" type="text/html" />
    <title>Markupslicer - Slice your HTML/CSS markup into Ruby on Rails layouts and partials.</title>
<summary type="html">&lt;p&gt;&lt;a href="http://markupslicer.com"&gt;http://markupslicer.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Supports ERB and HAML for now, vote on site for more formats. &lt;/p&gt;

&lt;p&gt;Beautifully crafted, totally free and it’s kinda fun. &lt;/p&gt;

&lt;p&gt;We originally came with the idea to skip this dull and dirty manual parsing and thought that others might find it useful as well. &lt;/p&gt;

&lt;p&gt;Play with &lt;a href="http://markupslicer.com/projects/demo"&gt;demo project&lt;/a&gt; and tell us how was it.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/knbuW_HMAvg" height="1" width="1"/&gt;</summary>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>michael</name>
    </author>
    <id>tag:blog.astrails.com,2010-04-13:321</id>
    <published>2010-04-13T15:56:00Z</published>
    <updated>2010-04-13T20:30:50Z</updated>
    <category term="Astrails" />
    <category term="nosql" />
    <category term="Ruby" />
    <category term="smallrecord" />
    <category term="activemodel" />
    <category term="activerecord" />
    <category term="cassandra" />
    <category term="nosql" />
    <category term="oss" />
    <category term="ruby" />
    <link href="http://blog.astrails.com/2010/4/13/smallrecord-simple-object-persistency-library-for-cassandra" rel="alternate" type="text/html" />
    <title>SmallRecord - Simple Object persistency library for Cassandra</title>
<summary type="html">&lt;p&gt;Simple Object persistency library for &lt;a href="http://cassandra.apache.org/"&gt;Cassandra&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home: &lt;a href="http://astrails.com/smallrecord"&gt;http://astrails.com/smallrecord&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="http://github.com/astrails/smallrecord"&gt;http://github.com/astrails/smallrecord&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Blog: &lt;a href="http://blog.astrails.com/smallrecord"&gt;http://blog.astrails.com/smallrecord&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Motivation &amp;amp; History (you can skip it :)&lt;/h1&gt;

&lt;p&gt;I was developing an multiplayer online game for a client (TBD: link when
released :) and we decided to use &lt;a href="http://incubator.apache.org/cassandra/"&gt;Cassandra&lt;/a&gt;
for performance and scaling benefits. Also the game’s internal data structures
mapped very well to key-value semantics.&lt;/p&gt;

&lt;p&gt;I did some research but couldn’t find anything that was &lt;strong&gt;Ready at the time&lt;/strong&gt;
to be used for development.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Simple Object persistency library for &lt;a href="http://cassandra.apache.org/"&gt;Cassandra&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home: &lt;a href="http://astrails.com/smallrecord"&gt;http://astrails.com/smallrecord&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="http://github.com/astrails/smallrecord"&gt;http://github.com/astrails/smallrecord&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Blog: &lt;a href="http://blog.astrails.com/smallrecord"&gt;http://blog.astrails.com/smallrecord&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Motivation &amp;amp; History (you can skip it :)&lt;/h1&gt;

&lt;p&gt;I was developing an multiplayer online game for a client (TBD: link when
released :) and we decided to use &lt;a href="http://incubator.apache.org/cassandra/"&gt;Cassandra&lt;/a&gt;
for performance and scaling benefits. Also the game’s internal data structures
mapped very well to key-value semantics.&lt;/p&gt;

&lt;p&gt;I did some research but couldn’t find anything that was &lt;strong&gt;Ready at the time&lt;/strong&gt;
to be used for development.&lt;/p&gt;
&lt;p&gt;I did find the &lt;a href="http://www.bigrecord.org/"&gt;BigRecord&lt;/a&gt; project which somewhat
kind of supported Cassandra, but I got an impression that Cassandra support was
‘bolted on’ after the fact, and their way of running a java Cassandra driver
talking to some JRuby and interfacing with it through DRB was … can’t quite
find the word for it, lets call it ‘awkward’ :).&lt;/p&gt;

&lt;p&gt;So I started to work on my own library, “steaing” liberally from BigObject,
which at least at the time was very close to ActiveRecord with just some
parts of the code commented out or replaced.&lt;/p&gt;

&lt;p&gt;Somewhere midway through the implementation I found the
&lt;a href="http://github.com/NZKoz/cassandra_object"&gt;CassandraObject&lt;/a&gt; project by
&lt;a href="http://github.com/NZKoz"&gt;NZKoz&lt;/a&gt;.  Now that was a much better one. So much
better that for some time I just considered dumping all I did and using it
as-is. After some thinking I decided against it though.  The primary reason was
that its data model was quite different from what I intended to use for the
game. In CassandraObject all attributes are stored as columns in a simple
&lt;a href="http://wiki.apache.org/cassandra/DataModel"&gt;ColumnFamily&lt;/a&gt;, and indexes and
associations stored in separate ColumnFamilies. This has a benefit of not
having restrictions on the number of associated object, but it does require
additional DB queries to access associated objects.&lt;/p&gt;

&lt;p&gt;I wanted to use
&lt;a href="http://arin.me/blog/wtf-is-a-supercolumn-cassandra-data-model"&gt;Supercolumns&lt;/a&gt;
instead, and store attributes and associations in different supercolumns for
the given key.  This has the benefit of being able to fetch all the data at
once, but does restrict the number of associated objects. Since in my intended
use-case the number of associations was rather small I decided to continue the
development.&lt;/p&gt;

&lt;p&gt;But, this doesn’t mean I didn’t use CassandraObject to “steal” some code from  it too :).
There were too many good ideas to pass by. I ended up copying a lot
of code from it and throwing all of the BigRecord heritage. May be someday I’ll find
a way to ‘combine’ SmallRecord back into CassandraObject. Meanwhile though I’m going
to work on this one.&lt;/p&gt;

&lt;p&gt;(Ugh, that ended up being rather long explanation :)&lt;/p&gt;

&lt;h2&gt;Status&lt;/h2&gt;

&lt;p&gt;This is work in progress. It is currently used in a client project and works
well, but it still has rough edges and might have problems in your specific
environment.  The code base is quite small and modular though, so you should
have no problems jumping in and fixing or extending it for your use case.&lt;/p&gt;

&lt;h2&gt;Data Model&lt;/h2&gt;

&lt;p&gt;This library is intended to be used with Supercolumns Families only (for now :).&lt;/p&gt;

&lt;p&gt;Model’s attributes are stored inside “attributes” supercolumn, with attributes themselves
being columns inside it. Associations are stored as separate supercolumns, with each association
id being a column inside.&lt;/p&gt;

&lt;p&gt;Example (json notation):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;users: {
  "1": {
    "attributes": {
      "name": "Vitaly Kushner",
      "company": "Astrails"
    },
    "account_ids": {
      "123": "1",
      "456": "1"
    }
}

accounts: {
  "123": {
    "url": "http://astrails.com",
    "username": "vitaly",
    "password": "234987234509827345"
  },
  "456": {
    "url": "http://rubyonrails.org",
    "username": "vitaly",
    "password": "3084573945873945"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see we have a one-to-many association here. but contrary to how it is handled
in ActiveRecord we don’t store the user_id in the account ‘record’, instead we store all the
account_ids in the user record. This is because otherwise we would have no way of querying user.accounts
except for the full accounts ‘table’ scan.&lt;/p&gt;

&lt;h2&gt;Implementation&lt;/h2&gt;

&lt;h3&gt;Connecting to the DB&lt;/h3&gt;

&lt;p&gt;SmallRecord will look for the file config/small_record.yml :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;production:
  adapter: cassandra
  host: 127.0.0.1
  port: 9160
  keyspace: astrails 

development:
  adapter: mock

test:
  adapter: mock
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Notice the :mock adapter. This is just a simple
Cassandra emulation using in-memory ruby hash. This is what I’m using
for development and testing. It doesn’t require cassandra running.
The emulation is not 100% off course but it does the job. And I didn’t
yet have any bugs related to the difference b/w the mock and the real thing.
Just remember that if you run develoment server with mock all the data will be gone
once you restart. But that is probably not such a bad thing for development. Or
it is. You decide.&lt;/p&gt;

&lt;h3&gt;Basics&lt;/h3&gt;

&lt;p&gt;You define your models the usual way:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User &amp;lt; SmallRecord::Base
  ...
end

user = User.new :foo =&amp;gt; "bar"
user.save
User.find(user.id)
User.first
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Attributes&lt;/h3&gt;

&lt;p&gt;What is different from the ActiveRecord is that you have to tell SmallRecord
about all your attributes since it can’t infer it from the database schema like
ActiveModel does. There is no database schema duh!  The attributes support
mostly came form CassandraObject but changed quite a bit since then. One day
I’ll document the differences :)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User &amp;lt; SmallRecord::Base
  attribute :name
  attribute :age, :type =&amp;gt; :integer
  attribute :create_at, :type =&amp;gt; :time
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;ActiveModel&lt;/h3&gt;

&lt;p&gt;This library is built upon Rails’s ActiveModel pulling in many of the familiar features of
the ActiveRecord. The following is supported:&lt;/p&gt;

&lt;h4&gt;Callbacks&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;before_save :do_something
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The following callbacks are supported:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    :before_init,    :after_init,
    :before_find,    :after_find,
    :before_save,    :after_save,
    :before_create,  :after_create,
    :before_update,  :after_update,
    :before_destroy, :after_destroy,
    :before_validation,
    :before_validation_on_create,
    :before_validation_on_update
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can also define your own callbacks:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User &amp;lt; SmallRecord::Base
  define_callbacks :after_activation

  after_activation :send_confirmation

  def activate!
    ...
    run_callbacks(:after_activation)
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;Dirty attributes&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; user.changed
=&amp;gt; []
&amp;gt;&amp;gt; user.name = "foo"
=&amp;gt; "foo"
&amp;gt;&amp;gt; user.changed
=&amp;gt; ["name"]
&amp;gt;&amp;gt; user.name_changed?
=&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When saving an object it will only save changed attributes:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; user.save
=&amp;gt; true
&amp;gt;&amp;gt; user.name = "qwe"
=&amp;gt; "qwe"
&amp;gt;&amp;gt; user.save
  User Insert (0.000043)   insert(aa421ea0-c407-46fe-986f-09b2d749b1be, {"attributes"=&amp;gt;{"name"=&amp;gt;"\"qwe\"", "schema_version"=&amp;gt;"0"}}, {})
=&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;Validations&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;class User &amp;lt; SmallRecord::Base
  validates_presence_of :name
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;Associations&lt;/h4&gt;

&lt;p&gt;Association support in SmallRecord is rather basic. Only has_many is supported at the moment (feel free to add more :).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User &amp;lt; SmallRecord::Base
  has_many :accounts
end

user.accounts
user.accounts.create
user.create_account
user.account_ids
user.accounts.first
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;SmallRecord tries hard to do the minimal required amount of work. the association is
lazily loaded and only when really needed.&lt;/p&gt;

&lt;h4&gt;Migrations&lt;/h4&gt;

&lt;p&gt;Migrations are very different then what you are used to with ActiveRecord (this is too comes from CassandraObject).&lt;/p&gt;

&lt;p&gt;You see, there might be a LOT of records in a Cassandra DB. To the point of it being quite impractical to run
a full migration. Instead each ‘record’ contains its schema-version and we migrate it on read if its outdated.
i.e. if we load a record into memory with schema_version that is less then the currently defined in the code
we will migrate &lt;strong&gt;this record&lt;/strong&gt;. If you save the record after that it will be saved with the updated version.&lt;/p&gt;

&lt;p&gt;migrations are defined using blocks:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User
  migrate 1 do |attrs|
    attrs[:foo] = attrs.delete(:bar)
  end
  ...
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;More&lt;/h4&gt;

&lt;p&gt;Read the code :)&lt;/p&gt;

&lt;h4&gt;TODO&lt;/h4&gt;

&lt;p&gt;There are a couple of things that I want to fix first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The elephant in the room is the total lack of testing! Well, in the project I’m
extracting this from the test coverage is quite high, so all the code was implicitly
tested, but now that this is a separate project I need to add some specs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is this ugly read/write_data business. Apart from the bad naming
(I still can’t think of a good one) all the supercolumns except for the
‘attributes’ are not managed.  They are currently written directly into db on
every change. Need to unify the ‘dirty’ handling in attributes with the rest
of supercolumns. For that I think I’ll need to drop the Dirty mixin from the
ActiveModel and just roll my own.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Documentation. This is also lacking at the moment and you will need to look at the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Need to research the possibility of merging with CassandraObject. Thought I’m not sure this
is practical.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Copyright&lt;/h2&gt;

&lt;p&gt;Copyright (c) 2010 Astrails Ltd. See LICENSE for details.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/9ZbEHPcXrQs" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>michael</name>
    </author>
    <id>tag:blog.astrails.com,2010-03-22:311</id>
    <published>2010-03-22T15:19:00Z</published>
    <updated>2010-03-22T15:20:08Z</updated>
    <category term="Astrails" />
    <category term="JS" />
    <category term="nosql" />
    <category term="Rails" />
    <category term="Ruby" />
    <category term="cassandra" />
    <category term="israel" />
    <category term="markupslicer" />
    <category term="outspokes" />
    <category term="ruby group" />
    <link href="http://blog.astrails.com/2010/3/22/israel-ruby-group-meeting" rel="alternate" type="text/html" />
    <title>Israel Ruby Group Meeting - Mar 2010</title>
<summary type="html">&lt;p&gt;About a week ago about 15 people were gathered in &lt;a href="http://www.pc.co.il/"&gt;People and Computers&lt;/a&gt; offices thanks to &lt;strong&gt;Raphael Fogel&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jerry Cheung&lt;/strong&gt;, nice guy from &lt;a href="http://outspokes.com"&gt;Outspokes&lt;/a&gt;, told everyone how Outspokes was built from the inside and shared his view on building javascript intensive application with Rails as a backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Outspokes&lt;/strong&gt; uses fancy javascript to allow in-browser collaboration of development/design/client teams to request changes, track progress and report problems on ongoing project. I definitely will try it out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boris Nadion&lt;/strong&gt; from &lt;strong&gt;Astrails&lt;/strong&gt; (that’s us in case you were wondering) told the story of our own &lt;a href="http://markupslicer.com/"&gt;MarkupSlicer&lt;/a&gt; - free to use project we wrote to simplify creating ERB/HAML layouts and partials out of HTML markup we get from our slicing team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vitaly Kushner&lt;/strong&gt;, also from &lt;strong&gt;Astrails&lt;/strong&gt;, made a nice intro presenation about &lt;a href="http://cassandra.apache.org/"&gt;Cassandra&lt;/a&gt; - our choice of &lt;a href="http://en.wikipedia.org/wiki/Nosql"&gt;NoSQL&lt;/a&gt; breed. We working with yet to be disclosed client on very technologically challenging project and cassandra is one of many interesting solutions we working with (You can expect a case study on this project in couple of months, as soon as it will go public).&lt;/p&gt;

&lt;p&gt;&lt;a href="/assets/2010/3/22/CassandraIntro.pdf"&gt;Cassandra Intro presentation&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/QUve_mtFDRQ" height="1" width="1"/&gt;</summary>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2010-01-21:291</id>
    <published>2010-01-21T22:20:00Z</published>
    <updated>2010-01-21T22:21:28Z</updated>
    <category term="Astrails" />
    <category term="astrails-safe" />
    <category term="IT" />
    <category term="astrails-safe" />
    <category term="backup" />
    <category term="enctyption" />
    <category term="gpg" />
    <category term="safe" />
    <link href="http://blog.astrails.com/2010/1/21/astrails-safe-0-2-7" rel="alternate" type="text/html" />
    <title>astrails-safe 0.2.7</title>
<summary type="html">&lt;p&gt;There is a new (0.2.7) version of Astrails-Safe.&lt;/p&gt;

&lt;p&gt;New features since 0.2.5:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;default options for gpg now include '--no-use-agent'&lt;/li&gt;
&lt;li&gt;support for 'command' option for gpg&lt;/li&gt;
&lt;li&gt;quote values in mysql password file&lt;/li&gt;
&lt;li&gt;add 'lib' to $:&lt;/li&gt;
&lt;li&gt;[EXPERIMENTAL] Rackspace Cloud Files support&lt;/li&gt;
&lt;/ul&gt;</summary><content type="html">
            &lt;p&gt;There is a new (0.2.7) version of Astrails-Safe.&lt;/p&gt;

&lt;p&gt;New features since 0.2.5:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;default options for gpg now include '--no-use-agent'&lt;/li&gt;
&lt;li&gt;support for 'command' option for gpg&lt;/li&gt;
&lt;li&gt;quote values in mysql password file&lt;/li&gt;
&lt;li&gt;add 'lib' to $:&lt;/li&gt;
&lt;li&gt;[EXPERIMENTAL] Rackspace Cloud Files support&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://github.com/minter"&gt;H. Wade Minter&lt;/a&gt; contributed support for Rackspace cloud files. I have no way of testing this, so please tell me if it works :)&lt;/p&gt;

&lt;p&gt;To easy the development process, I added the 'lib' directory of the 'currently running' safe to the library load path"$:". This enables to work on a new version of safe even though you have some version already installed. The files in ./lib will come first in the load path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT:&lt;/strong&gt; I just stumbled upon a problem with the gpg encryption on a freshly installed Ubuntu EC2 instance. the gpg was asking for a password on the console even though it was passed the --passphrase-file option with the file containing the password. After some investigation I found out that gnupg's default template configuration file now contains 'use-agent' options. The result of it is that on the &lt;em&gt;first&lt;/em&gt; invocation of astrails-safe it will work, but gpg will create a new ~/gnupg/gpg.conf file with 'use-agent' setting, so the next time you run astrails-safe it will fail and ask for  the password on the console!&lt;/p&gt;

&lt;p&gt;if you are running gpg 1.x series, just pass '--no-use-agent" to the "options" setting in the astrails-safe config in the 'gpg' section (since this 0.2.7 version this options is set in the default astrails-safe template config).&lt;/p&gt;

&lt;p&gt;For gpg2 series, I suppose you'll need to run the gpg-agent (actually I'm not sure, I didn't research it too deeply, so I'll be happy to get feedback on the issue)&lt;/p&gt;

&lt;p&gt;I also added 'command' option support for gpg which allows to override the executable astrails-safe is using for the enctyption. For example you can have "command "/usr/loca/bin/gpg" in the gpg section.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/t6DIXAkMhIA" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2010-01-14:281</id>
    <published>2010-01-14T00:49:00Z</published>
    <updated>2010-01-14T16:34:22Z</updated>
    <category term="Rails" />
    <category term="Ruby" />
    <category term="magic" />
    <category term="metaprogramming" />
    <category term="ruby" />
    <link href="http://blog.astrails.com/2010/1/14/there-is-no-magic-indeed" rel="alternate" type="text/html" />
    <title>There is no magic, indeed.</title>
<content type="html">
            &lt;p&gt;I’ve just read ”&lt;a href="http://gilesbowkett.blogspot.com/2009/07/do-you-believe-in-magic.html"&gt;Do You Believe In Magic?&lt;/a&gt;” and the following quote resonated particularly well:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;“It’s not magic. There is no magic involved. It’s just, if you never learnt Lisp,
    then you never learned to program, and Ruby’s power is exposing a deficiency in your skills.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I find it to be very true, and I suppose one of the reasons I’m so happy about Ruby is that I learned Lisp and Scheme before.&lt;/p&gt;

&lt;p&gt;Even though I didn’t use Lisp for any sizable project. I tried, but I found it to be quite unfriendly and ‘hairy’ in setup, environment and library support. Ruby solved all that for me w/o sacrificing almost anything power vise.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/JFT2Jj9Lv4g" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>michael</name>
    </author>
    <id>tag:blog.astrails.com,2009-12-16:251</id>
    <published>2009-12-16T17:45:00Z</published>
    <updated>2009-12-17T17:49:18Z</updated>
    <category term="jobthejob" />
    <category term="startup weekend" />
    <link href="http://blog.astrails.com/2009/12/16/jobthejob-starts-the-startup" rel="alternate" type="text/html" />
    <title>JobTheJob starts the startup</title>
<content type="html">
            &lt;p&gt;The opportunity: 120 happy dreamers cooking for 54 hours of pure startup joy, well-fed and ready to work. Of course, I’m talking here about Startup Weekend Israel.&lt;/p&gt;


	&lt;p&gt;The challenge: Come up with an idea that can be implemented in a couple of days, yet is so cool, so innovative, and so useful that I could attract the best of the best.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://blogtheblog.jobthejob.com/2009/12/startupthestartup.html"&gt;Read the rest at blogtheblog.jobthejob.com&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;P.S Now we have some pictures too there, you should &lt;a href="http://blogtheblog.jobthejob.com/2009/12/startupthestartup.html"&gt;check it out&lt;/a&gt;&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/PglJV6yZpK0" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2009-12-16:241</id>
    <published>2009-12-16T12:20:00Z</published>
    <updated>2009-12-17T17:38:57Z</updated>
    <category term="Astrails" />
    <category term="jobthejob" />
    <category term="startup weekend" />
    <link href="http://blog.astrails.com/2009/12/16/job-the-job" rel="alternate" type="text/html" />
    <title>Job the Job</title>
<summary type="html">&lt;p&gt;If you follow us on twitter (&lt;a href="http://twitter.com/astrails"&gt;@astrails&lt;/a&gt; if you wondering) you already know that we are at the &lt;a href="http://israel.startupweekend.org/"&gt;Startup Weekend Israel&lt;/a&gt; right now.&lt;/p&gt;


	&lt;p&gt;Which is going amazing by the way, thanks for asking, lots and lots of nice people, very creative and energetic atmosphere, food and beer.&lt;/p&gt;


	&lt;p&gt;Turns out our idea attracted a great team of developers, designers and business developers.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;If you follow us on twitter (&lt;a href="http://twitter.com/astrails"&gt;@astrails&lt;/a&gt; if you wondering) you already know that we are at the &lt;a href="http://israel.startupweekend.org/"&gt;Startup Weekend Israel&lt;/a&gt; right now.&lt;/p&gt;


	&lt;p&gt;Which is going amazing by the way, thanks for asking, lots and lots of nice people, very creative and energetic atmosphere, food and beer.&lt;/p&gt;


	&lt;p&gt;Turns out our idea attracted a great team of developers, designers and business developers.&lt;/p&gt;
&lt;p&gt;The idea is very simple: aggregate job postings from various sources (starting with twitter)
with automated translation to several languages (for now Hebrew, English and Russian) and automated tagging and display all on a web page with free text search and categories browsing.&lt;/p&gt;


	&lt;p&gt;It should make searching for a job a little bit less of a hassle as now you have to scavenge less sources to find your perfect job.&lt;/p&gt;


	&lt;p&gt;Why is it good for Startup Weekend:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Easy to explain&lt;/li&gt;
		&lt;li&gt;Is actually useful, solving real people pains.&lt;/li&gt;
		&lt;li&gt;Most importantly it really can be implemented within the constrains of the
   Startup Weekend (it seems like we’ll have only about 10-15 working hours on it)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The name of the service is &lt;a href="http://jobthejob.com"&gt;JobTheJob&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;So the team members are:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Me (Vitaly :) and Boris, obviously. Doing backend.&lt;/li&gt;
		&lt;li&gt;Michael can’t participate as he’s on the judges panel :)&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://punia.net"&gt;Pavel Kostychev&lt;/a&gt; is doing the UI &amp; identity.&lt;/li&gt;
		&lt;li&gt;Alan Rubin (backend)&lt;/li&gt;
		&lt;li&gt;Elyon DeKoven (front end, research, and all around)&lt;/li&gt;
		&lt;li&gt;Pini Sternshos (biz dev, marketing, etc)&lt;/li&gt;
		&lt;li&gt;Boris Reitman (front end)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;We created a blog for the new company, it’s called &lt;a href="http://blogtheblog.jobthejob.com"&gt;BlogTheBlog&lt;/a&gt; of course. You can grab our progress and impression there and i also will be posting links here when there is a new content there, so you can check out &lt;a href="/jobthejob"&gt;JobTheJob category&lt;/a&gt; on this blog. Also we will be &lt;a href="http://twitter.com/astrails"&gt;tweeting about it&lt;/a&gt;, and our personal twitter accounts(look to your right) so you welcome to follow the startup creation process in real time and if you have something to say about it we will be glad to hear.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/CnjZtBSXPEg" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>boris</name>
    </author>
    <id>tag:blog.astrails.com,2009-11-22:231</id>
    <published>2009-11-22T18:07:00Z</published>
    <updated>2009-11-22T18:10:02Z</updated>
    <category term="Astrails" />
    <link href="http://blog.astrails.com/2009/11/22/startup-weekend-comes-to-israel" rel="alternate" type="text/html" />
    <title>Startup Weekend Comes to Israel</title>
<summary type="html">&lt;p&gt;&lt;a href="http://israel.startupweekend.org/"&gt;Startup Weekend&lt;/a&gt; comes to Israel.&lt;/p&gt;

&lt;p&gt;The event will take place at IBM offices in Petch Tikva from Dec-16 to Dec-18. We are going to participate and also sponsor the &lt;a href="http://israel.startupweekend.org/"&gt;event&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Startup weekends are known to be a good place to network with all those startup people, like enterpreneurs, VCs, lawyers, developers and designers. &lt;/p&gt;

&lt;p&gt;Israeli event seems to be kosher, so it’s not exactly a weekend: Wed - Fri :-) Grab your &lt;a href="http://israel.startupweekend.org/tickets/"&gt;discounted ticket&lt;/a&gt; using discount code &lt;i&gt;swearlybird&lt;/i&gt;, and as they say you should bring “laptop, good attitude, and creative energy” there.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="http://twitter.com/swisrael"&gt;Startup Weekend Israel&lt;/a&gt; tweets to stay updated.&lt;/p&gt;

&lt;p&gt;We will &lt;a href="http://twitter.com/astrails"&gt;tweet&lt;/a&gt; our impressions and blog about them here.&lt;/p&gt;

&lt;p&gt;Looking forward to have some geek fun.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/wAhfwLIb9Yc" height="1" width="1"/&gt;</summary>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2009-11-12:221</id>
    <published>2009-11-12T23:50:00Z</published>
    <updated>2009-11-16T17:57:56Z</updated>
    <category term="nosql" />
    <category term="osx" />
    <category term="cassanrda" />
    <category term="java" />
    <category term="nosql" />
    <category term="osx" />
    <link href="http://blog.astrails.com/2009/11/12/cassandra-on-osx" rel="alternate" type="text/html" />
    <title>Cassandra on OSX</title>
<content type="html">
            &lt;p&gt;We just started a project for a client that involves &lt;a href="http://incubator.apache.org/cassandra/"&gt;Cassandra&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’ve been living under a rock and don’t know what Cassandra is let me tell you :)&lt;/p&gt;

&lt;p&gt;Cassandra is a “second-generation distributed database” that was built for web scale.
Its is one of the many distributed &lt;a href="http://www.google.com/search?q=nosql"&gt;nosql&lt;/a&gt; databases that
appear everywhere lately like mushrooms after a heavy rain :).&lt;/p&gt;

&lt;p&gt;What sets Cassandra apart is that it comes from a recognizable entity - Facebook.&lt;/p&gt;

&lt;p&gt;But I digress. This is not meant to be a Cassandra introduction, there are enough of those on the net.
I Just created a new &lt;a href="/nosql"&gt;nosql section&lt;/a&gt; on this blog where I’m going to post various tidbits of information
about cassandra (and probably others) as I learn them while working on this new project.&lt;/p&gt;

&lt;p&gt;Here is the first one:&lt;/p&gt;

&lt;h3&gt;Cassandra gem is just an installer&lt;/h3&gt;

&lt;p&gt;If you are on Mac OSX and interested in Cassandra you probably know that its just a gem installation away (almost):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install cassandra
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;First thing to note though is that this will &lt;strong&gt;not&lt;/strong&gt; install Cassandra. It will install cassandra &lt;strong&gt;installer&lt;/strong&gt;! I got bitten by this when I took my laptop with me to my doughter’s dancing class. You see, parents are not allowed “in the room” to not interfere with the process :), so I have 45 minutes to find myself something to do each time. I installed cassandra gem at home and intended to play with Cassandra while there. Not so fast. When I run &lt;code&gt;cassandra_helper cassandra&lt;/code&gt; which is supposed to start a test cassandra instance it went to connect to a github repository to download and install the actual database. Duh!&lt;/p&gt;

&lt;p&gt;and the 2nd one:&lt;/p&gt;

&lt;h3&gt;Use java preferences&lt;/h3&gt;

&lt;p&gt;When I got back and finally built Cassandra I got the following message when starting it for the first time:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~ &amp;gt; cassandra_helper cassandra
Set the CASSANDRA_INCLUDE environment variable to use a non-default cassandra.in.sh and friends.
(in /Library/Ruby/Gems/1.8/gems/cassandra-0.5.6.2)
You need to configure your environment for Java 1.6.
If you're on OS X, just export the following environment variables:
  JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"
  PATH="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin:$PATH"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;First thing to note is that just typing &lt;code&gt;JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"&lt;/code&gt; in the terminal wont help.
You need to &lt;strong&gt;export&lt;/strong&gt; it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"
PATH="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin:$PATH"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;No need to export PATH as its already exported.&lt;/p&gt;

&lt;p&gt;But there is a better and simpler way!&lt;/p&gt;

&lt;p&gt;Start “Java Preferences” (find it in /Applications/Utilities, or just use spotlight):&lt;/p&gt;

&lt;p&gt;&lt;img src="http://blog.astrails.com/assets/2009/11/12/Picture_2.png" alt="Java Preferences: Java 6 2nd" /&gt;&lt;/p&gt;

&lt;p&gt;Then reorder the entries in the bottom “Java Applications” section so that Java 6 will be the 1st:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://blog.astrails.com/assets/2009/11/12/Picture_3.png" alt="Java Preferences: Java 6 1st" /&gt;&lt;/p&gt;

&lt;p&gt;Now cassandra starts right away w/o any exports:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~ &amp;gt; cassandra_helper cassandra
Set the CASSANDRA_INCLUDE environment variable to use a non-default cassandra.in.sh and friends.
(in /Library/Ruby/Gems/1.8/gems/cassandra-0.5.6.2)
CASSANDRA_HOME: /Users/vitaly/cassandra/server
CASSANDRA_CONF: /Library/Ruby/Gems/1.8/gems/cassandra-0.5.6.2/conf
Listening for transport dt_socket at address: 8888
...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cool, now go write your killer application!&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/rzp3cAjbgjc" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://blog.astrails.com/">
    <author>
      <name>vitaly</name>
    </author>
    <id>tag:blog.astrails.com,2009-10-27:181</id>
    <published>2009-10-27T11:06:00Z</published>
    <updated>2009-10-27T18:40:54Z</updated>
    <category term="Rails" />
    <category term="controller" />
    <category term="design" />
    <category term="model" />
    <category term="mvc" />
    <category term="rails" />
    <category term="ruby" />
    <category term="url_for" />
    <category term="xml" />
    <link href="http://blog.astrails.com/2009/10/27/liberate-my-controller" rel="alternate" type="text/html" />
    <title>Let my controller go or useful impurity in software design.</title>
<summary type="html">&lt;p&gt;Yeah, I know, MVC is the “Only True Way”. But sometimes, just sometimes, you need your &lt;code&gt;link_to&lt;/code&gt; or html helpers working in the model.&lt;/p&gt;

&lt;p&gt;For example, sometimes the cleanest way to implement something is to have &lt;code&gt;to_html&lt;/code&gt; in the model (widgets anyone?).
Doing this will most probably require generating some urls, and you need a controller for that.
Usually I solved this by passing controller to the to_html function, but it always felt wrong.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Yeah, I know, MVC is the “Only True Way”. But sometimes, just sometimes, you need your &lt;code&gt;link_to&lt;/code&gt; or html helpers working in the model.&lt;/p&gt;

&lt;p&gt;For example, sometimes the cleanest way to implement something is to have &lt;code&gt;to_html&lt;/code&gt; in the model (widgets anyone?).
Doing this will most probably require generating some urls, and you need a controller for that.
Usually I solved this by passing controller to the to_html function, but it always felt wrong.&lt;/p&gt;
&lt;p&gt;Another example is when you are working on an API. You somtimes would like to have an option to add actual URIs of related services inside an xml.
Like in 
 &lt;pre&gt;&lt;code&gt;   &amp;lt;articles&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;title&amp;gt;Let my controller go&amp;lt;/title&amp;gt;
            &amp;lt;href&amp;gt;http://example.com/articles/123&amp;lt;/href&amp;gt;
            &amp;lt;created-at&amp;gt;2009-05-24T19:09:06Z&amp;lt;/created-at&amp;gt;
        &amp;lt;/article&amp;gt;
    &amp;lt;/articles&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Now how will you implement that? It would be nice if &lt;code&gt;@articles.to_xml&lt;/code&gt; just worked, but then how will you generate the href url?
&lt;code&gt;url_for&lt;/code&gt; is not available in models.&lt;/p&gt;

&lt;p&gt;Solution? just make it global and let the purists tear their hairs out! :)&lt;/p&gt;

&lt;p&gt;This plugin solves the issues above by making the current controller available from a global function &lt;code&gt;current_controller&lt;/code&gt;.
(actually it uses Thread local storage, so it will work even in multithreaded Rails environment)&lt;/p&gt;

&lt;p&gt;The installation is simple&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;script/plugin install git://github.com/astrails/let_my_controller_go.git
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;braid -p git://github.com/astrails/let_my_controller_go.git
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then you can implement the above as&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Article &amp;lt; ActiveRecord::Base
  def href
    current_controller.url_for(self)
  end

  def to_xml(opts = {})
     super opts.merge(:methods =&amp;gt; :href, :only =&amp;gt; [:title, :created_at])
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then &lt;code&gt;Articles.all.to_xml&lt;/code&gt; will produce what you need (when running in a context of a web request, i.e. it won’t work from the console).&lt;/p&gt;

&lt;p&gt;So, while it might not pass strict software design review, but it is useful. And as with any tool, it’s up to you to use it appropriatly. &lt;/p&gt;

&lt;p&gt;Sources are at &lt;a href="http://github.com/astrails/let_my_controller_go"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;OK, flame away! /ducks and hides under the desk/&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/Astrails/~4/Qvnib5TSGRw" height="1" width="1"/&gt;</content>  </entry>
</feed>
