Ruby's Hidden do {} while () Loop
archive.jvoorhis.com2 pointsby jz1 comments
require 'action_controller/integration'
app = ActionController::Integration::Session.new
module CurrentUserHack
def current_user
@user ||= User.look_up_my_user_here
end
end
ApplicationController.send :include, CurrentUserHack
Now you can make authenticated requests in rake tasks and presumably in script/runner.
This is an interesting point which I agree with and is usually where I end up. In the past I've started from the opposite end, creating multiple modules, class hierarchies, etc. This future proofing has made things harder for me to follow/understand when reading at a later date. It has become tiresome and now I consciously start at the other end, making the simplest thing that could work. Layers of abstraction then come naturally as needed.