basgren / railways

A plugin for RubyMine and IntelliJ IDEA Ultimate that adds a panel with routes of Ruby on Rails application.
MIT License
46 stars 18 forks source link

Add environment setting #12

Closed ddnexus closed 9 years ago

ddnexus commented 9 years ago

Railways relies on the development environment, and if you don't have one it cannot work. We have several apps that just don't have any development configured since each developer uses his own. Adding a simple setting would allow its usage also in that case.

basgren commented 9 years ago

Thanks for the idea! I was thinking about it at the beginning of development, but never needed this, so it was forgotten. Do you switch often between environments or you just use one with custom name?

ddnexus commented 9 years ago

Good observation: we have to switch trough environments, so a per-app setting would be optimal, but if it is complex to implement, a manual switch could be enough.

ddnexus commented 9 years ago

I mean, the same app does not switch a lot, but different apps have different envs (including development for some)

basgren commented 9 years ago

I got it, thanks) It's not a problem to add separate setting for each application, I just was thinking about the place for this option. If you switch environments rarely, then I'll put it in the plugin config dialog, if you do this often, then plugin toolbar will be more suitable place for it.

ddnexus commented 9 years ago

Whatever is better for you :). Thanks!

basgren commented 9 years ago

@ddnexus, unfortunately, implementation may take some time. Current RubyMine API doesn't allow to set environment variables for running rake tasks (details here: https://devnet.jetbrains.com/thread/459419?tstart=0), so I need time to find a workaround for this. Sorry.

ddnexus commented 9 years ago

I see :(

I have a few possible work arounds:

  1. (currently not optimal and I didn't checked yet): Changing the rake task name to point to a custom routes task in the app. The problem now is that the task name is recorded centrally. Maybe you could save it on a per-project basis? That is not self contained, but easy enought to solve the problem.
  2. we could implement an overriding of the 'routes' task at the application code level, which should first set the right env and then run the original rake task. It should not be too complex, but it would be rake-version dependant since it would probably require to patch rake. As soon as I will get some time I will try to do it: maybe the same code could be included in the plugin?

On Thu, Dec 18, 2014 at 9:46 PM, Basil Gren notifications@github.com wrote:

@ddnexus https://github.com/ddnexus, unfortunately, implementation may take some time. Current RubyMine API doesn't allow to set environment variables for running rake tasks (details here: https://devnet.jetbrains.com/thread/459419?tstart=0), so I need time to find a workaround for this. Sorry.

— Reply to this email directly or view it on GitHub https://github.com/basgren/railways/issues/12#issuecomment-67495007.

ddnexus commented 9 years ago

sorry, I missed that the rake task setting IS a per-app setting! That solves the problem for now. We need just to add a simple task in the app. Something like the following:

task :custom_routes do
  Rails.env = 'custom_environment'
  Rake::Task['routes'].invoke
end

Thank you!

basgren commented 9 years ago

Thank you, @ddnexus, for your suggestions! I was thinking about overriding routes task, but decided that it would be unoptimal hack just to make IDE plugin work. But happily I remembered, that rake accepts environment variables as parameters, so both alternatives are the same:

$ RAILS_ENV=test rake routes
$ rake routes RAILS_ENV=test

While the first one cannot be done using RubyMine API, the second invocation is easily implemented, and also it's cross-platform (in Windows systems env. vars cannot be set using the first syntax). So yesterday I tested my suggestion and it worked! I need to polish several things yet, but you will see this new option in the next release and then you won't need extra rake task to make the plugin work. Thank you for your help!

basgren commented 9 years ago

@ddnexus , new version of Railways plugin is released. Please update it to 0.8.1 version and let me know if everything is OK with Rails environment settings.

ddnexus commented 9 years ago

I tried it and it's perfect. Thank you for the fast response!