The Ruby and Rails community linklog
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
Submit a post
Post Preview
Note: Only the first pargraph is shown on the front page and overly long paragraphs may be broken up.
Make writing Rspec custom matchers a breeze
To be fair, custom matchers in rspec are pretty easy as is: create a class that implements a few methods and then define a method to wrap that class. [more inside]
Ruby and Metaprogramming
Ruby is a lang that supports Metaprogramming effectively, and might be the best in that field. If you want to explore more on that topic, and how ruby can help you, then check this list of posts i wrote recently, i hope you will enjoy them
Why setting the default value of a Hash to be a Hash is wrong (use a block instead)
A quick tutorial on how to make the default of a hash a hash.
Get working quickly with a customised Rails project launcher
Always find yourself opening the same terminal windows and browser tabs when you start work on your Rails app? Try this script to automate the process. It’s a simple script using the rb-appscript gem.
Ruby and Internal DSLs
A Domain-specific language(DSL) is a computer language that’s targeted to a particular kind of problem, rather than a general purpose language that’s aimed at any kind of software problem continue here…
Fixjour: Another object mother
If nothing has felt quite right to you so far, check out Fixjour. It gives you the new_[model], create_[model] and valid_[model]_attributes methods and nothing else. Check out the README for more info.
Sanitize: A whitelist-based Ruby HTML sanitizer
Sanitize is a new whitelist-based HTML sanitizer for Ruby. Using a simple configuration syntax, you can tell Sanitize to allow certain elements, certain attributes within those elements, and even certain URL protocols within attributes that contain URLs. Any HTML elements or attributes that you don’t explicitly allow will be removed.
Leverage ActiveRecord with Non-Database Backed Objects
ActiveRecord comes with a lot of nice things that aren’t dependent on having a database backed model. The most obvious example of this is the validation framework baked into ActiveRecord. Also, there are several plugins which add some useful behavior to ActiveRecord objects but don’t rely on having a database. [more inside]
Scope Columns
ColumnScope to select only certain values from your DB. I often need only single attributes of an ActiveRecord instance. In the past I used something like select_values(SELECT_SQL) or find(:all, :select => SELECT_SQL_FRAGMENT).map! { |r| [r.title, r.teaser]} to conservativly get them. After some time I felt the redundant code tiring and wrote this tiny plugin on top of named scopes. Usage examples:
Article.selects(:title_and_teaser).with_author.all # => [<Article ...]
Product.ordered_by_name.select_all(:name_and_prize) # => [['Apple Pie', 3.80], ...]
You can find the source and more examples in my repository @ github.
Lockdown improvements
I’m working on a new version of Lockdown and would like to hear of any suggestions. more info…
In light of the Rails/Merb merge, how DHH is still being a jerk
http://skein.tumblr.com/post/66709064/its-about-the-ecology-stupid - The Rails/Merb merge isn’t necessarily a bad idea. But rails-core needs to actually have a conversation about why people (a number of merbists) were so pissed off at the rails community that they left. And that can’t happen until someone acknowledges that there was a legitimate problem.
Ruby callbacks
This blog post is about ruby’s callbacks(hooks): what are the available ones,and how practically we can use them? Ruby callbacks
Scalable Datasets with Bloom Filters and Ruby
When you’re working with large datasets it’s always nice to have a few algorithmic tricks up your sleeve, and Bloom Filters are exactly that - often overlooked, but an extremely powerful tool when used in the right context. Learn the theory and get started with Bloom Filters in Ruby.
Ever been confused by Leopard's patch level for Ruby?
In the comments on bryanl’s blog post, “So, if you are using a mac, wanna know why you are using the wrong ruby?”, Laurent Sansonetti explains the patch level for the Ruby version maintained by Apple.
Valid Attributes and Records for Unit/Integration testing
valid_attributes a Rails plugin that produces valid Records and attributes from a given yml file.
user = valid User #reord (unsaved)
strange_user = valid User, :name=>'Mr Strange' #slightly modified version...
Also Included: assert_invalid_attributes, a validation to test all validation rules DRY and with readable output.
#--> Failure: User.email expected to be invalid when set to s@sss
asser_invalid_attributes User, :email=>[nil,'','s@sss','xx@dd.s'], ...
Getting Started With Story testing in Cucumber
2 quick tutorials to get started with story-based testing, including some common steps and real-life-stories Cucumber Part 1 and Cucumber Part 2
Ruby reflection 2
This is the second post related to ruby’s reflection API, the previous post was an extensive intro to this topic. While the current one will be lighter somehow, it would require you to focus a bit more on the content. Here we go:
Another Ruby weather API - NOAA
A new gem for pulling current conditions and daily forecasts from the National Oceanic and Atmospheric Association’s weather service (a.k.a. weather.gov).
Ghetto contexts in Rails tests
If you’re between a rock and a hard place because you can’t add Shoulda or RSpec dependencies to your tests, check out this solution using lambdas.
Rails Monoculture Over
Foy Savas covers the Rails-Merb merge and what to make of it.
merb's provides/display in rails
DHH recently posted about bringing merb’s provides/display into rails. Here is my take with a few tweaks.
New rails plugin for easily adding emailed verifications to your models
Fixie Verifications is a Rails plugin that lets you add emailed verifications to your models. From the README: [more inside]