BlipTV API In Ruby

I recently needed to do some work for a client to integrate their site with blip. The blip tv wiki points ruby developers to a decent project. However, my needs were a lot more intricate than what the current gem covers. I forked the project and added in the functionality that I needed (as is the case for most open source needs). Along the way, I found out that bliptv has a json api. I couldn’t resist and converted the bliptv gem to leverage the json api. Probably a faux pas, but it is faster than rss/xml parsing. ...

October 14, 2009 · 1 min · 188 words · Brandon Harris

Why aren't you using Active Scaffold?

I do a lot of work creating admin interfaces in rails. A lot of it is redundant, so it would be nice to use a canned solution. Django has an admin interface built into every project. This makes a developers life easier. I thought “Wouldn’t it be nice to have a plugin that read all my table associations and provided a simple crud interface?” That is exactly what Active Scaffold tries to be. ...

July 7, 2009 · 2 min · 369 words · Brandon Harris

Populate Object Instance Variables From Hash

I recently needed to write a class in ruby that I wanted to behave similarly to an ActiveRecord based class, but without the database ties. Particularly, I wanted to do this: r = Record.new({:attribute1 => "a", :attribute2 => "b"}) It’s not too hard to hard code a simple class with attributes that are defined by a Hash, but in the pursuit of elegance, I wanted it to be more generic. I pulled up this little snippet: attributes.each do |k, v| if k.include?("(") multi_parameter_attributes << [ k, v ] else respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}") end end This is your most basic metaprogramming technique in ruby. Check if the object responds to the message, and if so, set it. ...

May 18, 2009 · 1 min · 154 words · Brandon Harris