My webapp should encrypt my session data. I am setting up:
config/initializers/encryptor.rb: require 'openssl' require 'myapp/encryptor' MyApp::Encryptor.config[ :random_key ] = OpenSSL::Random.random_bytes( 128 ) Session.delete_all app/models/session.rb: require 'attr_encrypted' class Session < ActiveRecord::Base attr_accessible :session_id, :data attr_encryptor :data, :key => proc { MyApp::Encryptor.config[ :random_key ] }, :marshal => true
Everything works fine and saves session data. This is where the problem arises: when I run my custom rake tasks, it loads the initializer and clears all sessions. Not good!
What can I add to my initializer to make sure that it ONLY runs to initialize the webapp? Or, what can I put in my initializer so that it does NOT start for rake tasks?
Update: OK, what have I done so far, adds MYAPP_IN_RAKE = true unless defined? MYAPP_IN_RAKE
MYAPP_IN_RAKE = true unless defined? MYAPP_IN_RAKE
to my .rake file. And then in my initializer I do:
unless defined?( MYAPP_IN_RAKE ) && MYAPP_IN_RAKE
It seems to need work. But I am open to other suggestions.
source share