Best Way to detect if you are in a migration?

I have a method where I would like output to occur via "puts" only if its currently in the middle of a rake task or if its in the middle of a migration.

How can I detect if the program execution is in the context of a migration or a rake task?

Anybody?

Not sure about this, but I think calling self.class or self.parent inside a migration task (self.up and self.down) should return ActiveRecord::Migration.

right, but Im talking about deep in the code, like in an ActiveRecord model lets say.

I im interested in this question, has somebody the answer?

I recently posted a similar question. No answer...

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/5d38a62129fa63e4/a78671aa145bf278?hl=en#a78671aa145bf278

Create your own class that inherits ActiveRecord::Migration and use it, defining the behavior you would like to have.

i once had a similar problem. in my case i wanted to skip some code whenever it is called from a rake task. back then i solved it the way Frantisek Psotka proposed. still working, no problems. just set your ENV-variable at the beginning of your rake task.