10

I am running a rails 3.1 app which uses an engine called 'awesome_engine'. Awesome_engine has some asset stuff I need to get at but compass's load paths do not include the engines assets path. My understanding is that it should be there, but it's not.

I need to add it so I modified my config/compass.rb to include compass's additional_import_paths config setting. The problem is, this is how I get the path to the required gem:

begin
  gem_root = $LOAD_PATH.find{|i| i.include?('/awesome_engine/')}.gsub(/awesome_engine\/.*/, 'awesome_engine/app/assets/stylesheets/scss')
  additional_import_paths = [gem_root]
rescue
end

This works but there has got to be an easier/better/cleaner way to get a gem's full path. Anyone?

ynkr
  • 25,946
  • 4
  • 32
  • 30

1 Answers1

26

Gem.loaded_specs is what I wanted:

ruby-1.9.2-p290 :001 > Gem.loaded_specs['awesome_engine'].full_gem_path
 => "/Users/younker/dev/engines/awesome_engine" 

ruby-1.9.2-p290 :002 > Gem.loaded_specs['rails'].full_gem_path
 => "/Users/younker/.rvm/gems/ruby-1.9.2-p290@foobar/gems/rails-3.1.3"
ynkr
  • 25,946
  • 4
  • 32
  • 30