In the latest What’s New in Edge Rails, there comes about a few interesting features in the works.
For Tyler … apparently ActiveModel (the superclass of ActiveRecord) has a state machine implementation? I wonder if it’s better than EventMachine which you oh-so-loathe?
ActiveRecord now has easy access to ActiveModel’sStateMachineimplementation. I don’t know about you, but somehow I always seem to find a way to bring state machines into my Rails applications, and now building in - even fairly complex - state machines just got a whole lot easier.
For an example ofActiveModel::StateMachineand to get an idea of how you might use it, check out my more detailed blog post over at Envy Labs.
For anyone … I really don’t understand the purpose of this feature:
Paul Gillard committed a patch which now allows for both custom suffixes (which really isn’t new) and prefixes (omg THAT IS!) on your ActiveRecord attributes. This gives you access to
attribute_method_prefix,attribute_method_suffix, and nowattribute_method_affix. While it may sound a little silly, check this out:class Person < ActiveRecord::Base attribute_method_affix :prefix => 'me_mateys_', :suffix => '_is_in_pirate?' private def me_mateys_attribute_is_in_pirate?(attr) send(attr).to_s =~ /\bYAR\b/i end end person = Person.find(1) person.name #=> 'Paul Gillard' person.profession #=> 'A Pirate, yar!' person.me_mateys_name_is_in_pirate? #=> false person.me_mateys_profession_is_in_pirate? #=> trueOkay, well, that’s still a little silly, but hopefully you get the idea and can think of a few usage scenarios of your own. So, basically, now you can add your own dynamic ActiveRecord methods that can potentially affect any or all of it’s attributes.
That seems rather pointless. A very convoluted and non-intuitive way of adding methods to your model.