19th
I recently needed to understand how beanstalkd works and how does it implement the distributed behaviour, so I did some reading.
From the beanstalkd main page:
beanstalkd is a fast, distributed, in-memory workqueue service
Ok, it is a distributed service, so let’s find some more info about its distributed nature.
This is what we can find in beanstalkd FAQ:
Does beanstalk inherently support distributed servers?
Yes, although this is handled by the clients, just as with memcached. The beanstalkd server doesn’t know anything about other beanstalkd instances that are running.
Using the same argumentation I could say that FTP or any database server is also distributed if you only start more than one instance. The fact some server allows to create scalable and distributed solutions, doesn’t necessarily mean that they are distributed on their own.
Here is how to run Haml’s unorthodox plugin generator method using Rails Templates:
Here is a sample Rails Template for fun:
module Foo
def self.included(base)
base.show_action(:custom_action)
end
def custom_action
"foo"
end
end
resources_controller takes you a long way into simplifying your controllers. Still, whenever you need to add custom collection or member routes to your app you’re out in the wild again. This snippet of code uses a combination of ActiveRecord’s named_scopes and resources_controller to simplify those custom actions. With a bit more of abtraction it could be turned into library code that you test once and reuse as many times as you want in different codebases.
The cool thing is that we get seamless nested controllers if we need them, such as in /posts or /users/2/posts
There’s not one but many ways of extending ActiveRecord. Some people do:
ActiveRecord::Base.send :include SomeModule
Which in turns includes or extends other modules.
Others extend first, and include internally. Others class_eval the hell out of everything.
There are a few gotchas to avoid, such as accidentally reloading the same modules (ie. in background tasks), which can cause havoc if your extensions uses method aliasing.
Looking at different approaches, I’ve come up with this draft of a convention.