Local Gem not treated as Library Home (Non project-files)

Hi,

We are developing a Rails project with multiple Rails Engines. The Engines are Gems, but they live in the same project.

App tree:
- main_app
-- app
-- engines
--- engine_app
---- app (library home)
---- lib (libary home)
---- Gemfile
-- Gemfile

main_app Gemfile:
gemspec(path: 'engines/engine_app')


engine_app Gemfile:
gemspec


If we want to work on the Engine, all cool RubyMine features like find references, find usages and refactor do not work anymore. These features are used all the time. The local gem is specified as a Library Home and isn't part of the project. But in our case it is a part of the project.

0
4 comments
Avatar
Oleg Sukhodolsky

Hi,

RubyMine doesn't support such project structure very well :( The only think I can suggest to try is to create separate project for engine_app and open it as a second project in main_app.

Hope this helps, Oleg.

0
Avatar
Martijn van Leeuwen

Hi Oleg,

The solution didn't work with an 2nd project. But we did have a breakthrough which we would like to share.

When you setup a project with this type of Gemfile:

source 'http://rubygems.org'


gem('engine', path: 'engines/engine_app')
gem('engine2', path: 'engines/engine2_app')


Rubymine (or rubygems) will register the gem engine as a external gem.

Gems used for 'main_app':
     engine2_app (0.1)
         ~/RailsProjects/websend/playground/main_app/engines/engine2_app
     bundler (1.3.5)
         ~/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5
     engine_app (0.1)
         ~/RailsProjects/websend/playground/main_app/engines/engine_app


Screen Shot 2014-03-20 at 10.53.12.png


When edit your Gemfile and you use this syntax

gemspec(path: 'engines/engine2_app')
gemspec(path: 'engines/engine_app')


Rubymine will still see this as a external gem.

If you move your directory to another directory for example main_app2 the gems become local again

Screen Shot 2014-03-20 at 10.58.11.png

The Gem Environment only sees bundler now as external gem

Gems used for 'main_app':
     bundler (1.3.5)
         ~/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5



So the workaround on this subject for now is: Don't use gem 'my-gem-name', path: 'local/path' for local gems.
0

This is exactly the problem I am having, but this workaround did not work for me.  Does this still work in the latest version of RubyMine (7.1.4)?

0

The following workaround will work in all cases and allows you to use gem 'foo', path: './components/foo' in your gemfile

In components/foo add the file foo.iml with the following contents:

<?xml version="1.0" encoding="UTF-8"?>

 
<module type="RUBY_MODULE" version="4">
<component name="NewModuleRootManager">
  <content url="file://$MODULE_DIR$" />
  <orderEntry type="inheritedJdk" />
  <orderEntry type="sourceFolder" forTests="false" />
</component>
</module>


Open .idea/modules.xml and add the follwoing

 
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/.idea/ag_biome.iml" filepath="$PROJECT_DIR$/.idea/ag_biome.iml" />
      <module fileurl="file://$PROJECT_DIR$/components/foo/foo.iml" filepath="$PROJECT_DIR$/components/foo/foo.iml" />
    </modules>
  </component>
</project>


Restart RM, and you should see components/foo as a part of the project.

Once you do this, you will need to open the Ruby SDK and Gems section of preferences and ensure that the foo sub-project is using the right SDK in RubyMine.

0

Please sign in to leave a comment.