05.03.08
alonetone
code, poetry, philosophy, folly
I work on Ruby on Rails plugins fairly often, and I’m always curious how people make their plugins configurable.
For example, ActiveMessaging uses several config files - some are yaml, some are ruby - all of them get loaded when the plugin gets initialized. ActiveMessaging has more than a bit of configuration, so distinct files for it makes sense. Also, it has less singular values that get set, and more sets of configuration values (e.g. all the values for a message broker connection).
Comatose uses a singleton with attributes that get defined in a block - so like the Rails initializer, you can call this define method in an environment.rb. Again, this makes sense, there are only a few values to fiddle with, and you very often don’t have to mess with them at all.
Not sure if I’ll use it, but I’ve been playing with an idea where you can use constants to override config values using constants. Makes sense for a plugin where you have default values that would rarely, and often individually, be overridden. Nice thing about this is that constants can be defined even before the config class, so if you need them to be set before the plugin is loaded, this provides a way.
Anyway, to make it easier, I wrote a little helper method to define class attributes, set the default value, and check for constants to override the default, all at one time.
class Config
class <<self
def set_config_value(var_sym, default=nil)
cattr_accessor var_sym
const_name = var_sym.to_s.upcase
value = (Object.constants.include?(const_name)) ? Object.const_get(const_name): default
class_variable_set("@@#{var_sym}".intern, value)
end
end
# SOME_CONFIG_VALUE set as a constant will override the default
set_config_value :some_config_value, "this is a default"
end
We had some fun folks from both the station/network side of PRX, and the independent producer side of the biz come hang out with us and talk about what to do next. Much of what we heard is now fermenting into the sweet brew of the next PRX release. For a non-PRX take on the meeting and the future of PRX, pull a few gems from the bag of insights that Todd Mundt left on his bloggy doorstep:
PRX has been around just long enough that now is good time to reassess strategy. That seems to be happening. But a few things are already clear: PRX is public radio’s fourth network; it’s the open source public radio network, and for those of us who are beginning to look for fresh, new voices to add to our schedules, it’s the best place to start.
With the Tapestry tap celebration this weekend, it’s just in the nick of time that the website for the Beantown Tapfest is now fleshed out.
I still need to spend some time making it prettier, adding images and such things, but most importantly it now has the list of events, and the online registration form which integrates with PayPal (Website Payments Standard in conjuntion with IPN). I am not a big PHP fan, but I do like being able to package up and deploy my new ‘pprf’ (PayPal Registration Form) plug-in to any WordPress site for testing. I need to make it a bit more generic, and add one more admin page, but hey, it works and I’ll probably release it as open source soon.
I’m mostly happy with the logo, as IANAD(esigner) - anything that comes from Illustrator out of my computer should be suspect, but I think the logo looks good.
Now on with the day, and hoping a get some rest before Tapestry classes kick my butt.
…it’s small, but found a bug in the new filter code in the ActionController for rails edge.
Showed up using habtm with ActiveScaffold - go figure.
Lesson learned - Array.insert should probably be named Array.insert! - it changes the underlying array, and sometimes that’s not what you mean to do.
http://dev.rubyonrails.org/ticket/8383
Now we’ll see if it gets committed.