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?
A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .
Gemfile is a file which must be located in root of your rails project. It is used for describing gem dependencies for Ruby programs. The first thing in your gemfile is a source in which you tell the Gemfile where to look for gems. Source can be called as a block and you can have multiple sources in your gemfile.
To use RubyGems to install gems, all you have to do is type gem install [the name of the gem you want to install] . RubyGems will then go ahead and install that gem for you from its library.
You may browse and search for gems using the RubyGems website, or use the gem command. Using gem search -r , you can search RubyGems' repository. For instance, gem search -r rails will return a list of Rails-related gems. With the --local ( -l ) option, you would perform a local search through your installed gems.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With