I''ve searched this group and google, but have not found the answer to my question. If there is a post about it somewhere, I''d greatly appreciate a link. I also started to dig into the rake code, but, frankly, didn''t understand it. Question: Why does it seem that :environment is required in order to have ActiveRecord::Base.configurations populated with the contents of database.yml. Explanation: namespace :phillip do task :mytask do ActiveRecord::Base.configurations.each_value do |config| p config[''database''] end end end prints nothing. Yet namespace :phillip do task :mytask => :environment do ActiveRecord::Base.configurations.each_value do |config| p config[''database''] end end end outputs the database names in my database.yml file. I understand that if I''m actually trying to do something, I''d need the environment. But it seems that the configurations would be available without knowing a specific environment. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
:environment is a task that loads up environment.rb. When you do task :foo => :environment you''re saying "my task depends on another task called :environment, so invoke that first , and then do my stuff" On Tue, Jul 1, 2008 at 1:10 PM, Phillip Koebbe < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''ve searched this group and google, but have not found the answer to my > question. If there is a post about it somewhere, I''d greatly appreciate > a link. I also started to dig into the rake code, but, frankly, didn''t > understand it. > > Question: > > Why does it seem that :environment is required in order to have > ActiveRecord::Base.configurations populated with the contents of > database.yml. > > Explanation: > > namespace :phillip do > task :mytask do > ActiveRecord::Base.configurations.each_value do |config| > p config[''database''] > end > end > end > > prints nothing. Yet > > namespace :phillip do > task :mytask => :environment do > ActiveRecord::Base.configurations.each_value do |config| > p config[''database''] > end > end > end > > outputs the database names in my database.yml file. > > I understand that if I''m actually trying to do something, I''d need the > environment. But it seems that the configurations would be available > without knowing a specific environment. > > Peace, > Phillip > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1 Jul 2008, at 19:10, Phillip Koebbe wrote:> prints nothing. Yet > > namespace :phillip do > task :mytask => :environment do > ActiveRecord::Base.configurations.each_value do |config| > p config[''database''] > end > end > end > > outputs the database names in my database.yml file. > > I understand that if I''m actually trying to do something, I''d need the > environment. But it seems that the configurations would be available > without knowing a specific environment. >Well at a very basic level, ActiveRecord::Base.configurations isn''t going to populate itself. rails isn''t even loaded if your task doesn''t depend on :environment Fred> Peace, > Phillip > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> :environment is a task that loads up environment.rb. > > When you do > > task :foo => :environment > > you''re saying "my task depends on another task called :environment, so > invoke that first , and then do my stuff"Thanks for the explanation, Brian. That makes much more sense now. I see that I was confusing a task with a variable/parameter/argument. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> > Well at a very basic level, ActiveRecord::Base.configurations isn''t > going to populate itself. rails isn''t even loaded if your task doesn''t > depend on :environment > > FredThanks, Fred. I''m understanding now. I haven''t ventured into rake until now and didn''t get it. I read through some of the rake docs, but apparently didn''t actually digest anything. Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for that Brian I didn''t know either! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---