The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Rails code that doesn't get executed for generations and migrations

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Andrew Montgomery

Posts: 42
Nickname: darkliquid
Registered: Sep, 2006

Andrew Montgomery is a lead developer for UK-based web development company SonicIQ
Rails code that doesn't get executed for generations and migrations Posted: Sep 22, 2006 5:31 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Andrew Montgomery.
Original Post: Rails code that doesn't get executed for generations and migrations
Feed Title: Dark Liquid - Ruby
Feed URL: http://feeds.feedburner.com/DarkLiquid-Ruby
Feed Description: Ruby and Rails related ramblings by Andrew Montgomery
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Andrew Montgomery
Latest Posts From Dark Liquid - Ruby

Advertisement

At work, we���ve developed some plugins that cause issues when invoked in generators. For instance, you may be creating controllers on the fly, and so when you what to generate a controller to override the automatic one, you can���t as it is ���reserved���.

Well, you can determine what context in which you code is being executed quite easily using built in globals in Ruby.

To elaborate on the boss���s original post


  $0 # returns the command executed to run this script, i.e. script/generate, rake, etc

  unless $0 =~ /generate$/
    puts "Code that wont run in generators goes here"
  end

  if $0 == 'rake' and ARGV[0] =~ /migrate$/
    puts "special code to be run in migrations, like some cool migrations enhancing plugin for instance"
  end

I���d love to wrap this in a nice plugin, patch or gem to enable cool things like this:


if ['db:migrate', 'db:schema:load', 'db:schema:dump'].include?(Rails.rake_task) or Rails.run_by?('script/generate')
  puts "do cool stuff"
end

Read: Rails code that doesn't get executed for generations and migrations

Topic: Want to Help Translate the Ruby Site? Previous Topic   Next Topic Topic: RoR persistency vs. JPA (Java SE/EE5) - or what is easier?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use