2 min read

Dispatch: A Day of Cleanup

With most of the pieces of the puzzle in place, I took today to go back over the codebase and remove artifacts of the refactoring work I've been doing, and spent some time renaming variables and methods I've created so they more accurately reflect what they're doing:

  • ActionView::Template had a render method on it in which almost every line was an instance_variable_get or send() into ActionView::Base. I (slowly, very very slowly) moved the method over into ActionView::Base.
  • Similarly, I moved the partial rendering code out of ActionView::RenderablePartial and onto ActionView::Base as well.
  • I reorganized ActionView, creating directories for "render" and "template", and moving the appropriate files into the directories. This should significantly reduce the amount of visual clutter in the action_view base directory and make it easier to find the part of the code you're looking for.
  • I was finally able to remove ActionView::Base#render_for_parts, which was the temporary shim I created when I started this round of refactoring to force all the callers into ActionView to call in with unified parameters. This was replaced with render_for_template yesterday (renamed to render_template_with_layout today), which means that the conduit between parts of ActionPack is now reduced to Template objects and layouts (also Template objects).
  • The reorganization I referenced above also moved common methods into common files. For instance, the ActionView methods related to top-level rendering are in render/rendering.rb, while the ones related to rendering partials are in render/partials.rb.
On another note, I've been playing with an interesting memoization technique that lets you declare the methods to be memoized in a block: ``` class Foo extend Memoizable

memoize do
def memoed(baz)
baz * 1000

def unmemoed(baz)
baz * 1000

After creating this class, Foo.new.memoed will be a memoized method, but creating the memoization will not use alias_method_chain. Instead, it uses normal Ruby structures, and super. You can see the full details in <a href="http://gist.github.com/45232">a gist I posted with the code</a>. It definitely gets a bit into the deep end of metaprogramming magic, but the end result is memoized methods that will retain their names in stack traces (probably my biggest personal gripe with alias_method_chain).

Finally, I'm going to start putting together a quick prototype of how Rails3 can be JavaScript agnostic while retaining the existing JS helpers next week some time. I've already gotten a lot of good feedback from the jQuery and Mootools communities, and plan to get as much involvement as possible as I move forward. Feel free to ping me (wycats on freenode or gmail) if you have any specific suggestions or just want to chat about the project. More details to follow next week :)