August 27, 2009

ruby block syntax

Reading a commit from DHH I found out a syntax I was not aware of.

Instead of doing:

[1,2,3,4,5,6,7,8,9,10].select { |x| x.even? }

You can do:

[1,2,3,4,5,6,7,8,9,10].select(&:even?)

When I asked in #rubyonrails irc channel about this syntax, I got enlightened: The first part is obvious: last argument starting with & is interpreted as a Proc and equivalent to passing a block, so it is not a &: operator but & and a symbol. How does the symbol work?

According to the people in the channel, it is rails magic. When I said that it works for me in irb I was told I must be running ruby 1.9, which I am not. After some discussion we realized this magic is in ruby 1.8.7 too.

The magic is of course, just Symbol#to_proc method ;-)

Rails engines and static assets (public/)

I was very happy that Rails Engines got merged in Rails 2.3. However I never liked that engines did not support overlaying static assets like they do with controllers, models and views. Even worse, the discussion was around “mirroring” the engine’s assets into the application public/ directory (like you can see in this railcast).

I imagined that doing something more transparent would be non-trivial. But I never asked myself why. When mentioning this limitation to Daniel when explaining how we use engines in our code, he asked the magical question: “Why?”.

I have been looking at Rails’s Rack support recently. I love Rack. And if you see how Rails builds its complex pieces over such simple components based on Rack, you realize how good Rack is for the Ruby community as a base component.

So, I tried the very first though: Create a Rake middleware called StaticOverlay that is initialized with various overlay directories. When the middleware is called it will look for the file in the overlays, and if it finds it in one, it will serve it (using Rack::File), if not, it just call the application (or next middleware in the chain).

Once I put the rack middleware together it worked out of the box, so I started a thread in rails core list to find out whether this would be a valid approach to hack a real patch and add support for this in Rails itself.

August 4, 2009

SUSE Appliance Program WebYaST alpha demo

Together with the launch of SUSE Studio 1.0, an alpha demo of WebYaST was also included in the Appliance Kit preview. We talked about WebYaST earlier this year. The demo includes small functionality like setting the system language, system time, patches/updates and general status of your appliance.

WebYaST mission is to add value to your appliance by providing the basic setup requiring only a web browser. The idea is that you build your appliance with Studio and include WebYaST so you can perform setup, configuration and basic monitoring.

The WebYaST demo is available as an appliance (built with SUSE Studio) on the Novell Appliance Program page. Advanced users can follow the YaST:Web repository on the openSUSE Build Service.

Built with SUSE Studio

Haven’t tried SUSE Studio yet? Here is a nice demonstration video.

If you are an ISV, you may also want to checkout the upcoming SUSE Lifecycle Management Server, everything you need to serve your appliance customers with your application plus operating system updates.

osc-plugin-overview 0.3 released

Packager’s favorite dashboard got a new version. Most patches were contributed by Michael Andres.

  • follow links to a package with different package name.
  • adapt to changed API to retrieve submitrequests.
  • support ‘changes=1′ in ini-inifile to print changelogs per section (like -c)
  • osc no longer takes the md5 as revision.
  • cleanup changelog diff temp files
  • suppress changelog diff if source does not provide changes ( like obssr)
  • let changes diff consider only repos that actually provide changes.

Get it from [the build service], or visit the home page here. You can read the introductory post here.

Kopete Facebook plugin 0.1.3 released

Available for openSUSE Factory in my home project. I also submitted to the KDE:KDE4:Factory:Desktop project where you may find it built for older releases using a newer KDE.

Changes:

  • Some connection fixes
  • The idle status icon is now shown
  • Basic user info widget (bug #198286)
  • Show contact status message! (bug #198284)
  • build system improvements
  • qjson 0.6.x is now required

Known bugs:

  • The plugin crashes when exiting Kopete. Some weird stuff with “myself” contact which seems to be deleted twice

Note: This plugin is not associated with Facebook in any way.