How can I tell if a vendored gem is being used?
ruby, ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.1, rubygems
Solution
A convenient way of checking this is by using a REPL. I would recommend installing the pry-rails gem, which will simply replace the default rails console (IRB) with the arguably more powerful Pry REPL.
#Gemfile
group :development do
pry-rails
end
Run `bundle install`, and than start the Rails console with `bundle exec rails c`. Once you are within Pry, you can use its built in `show-source` command to look up where a specific method has been implemented. Example:
>> show-source ActiveRecord::Base.establish_connection
From: /home/andrea/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb @ line 128:
Owner: #<Class:ActiveRecord::Base>
Visibility: public
Number of lines: 11
def self.establish_connection(spec = ENV["DATABASE_URL"])
resolver = ConnectionSpecification::Resolver.new spec, configurations
spec = resolver.spec
unless respond_to?(spec.adapter_method)
raise AdapterNotFound, "database configuration specifies nonexistent # {spec.config[:adapter]} adapter"
end
remove_connection
connection_handler.establish_connection name, spec
end
For more usage examples on how to use this specific built-in command, refer to Pry's inline `help` system:
help show-source
Or have a look at the Source browsing page, on Pry's wiki.
Problem
I have inherited an old project that was previously passed on by multiple developers. It's in a bad shape so I'm trying to bring it back to life. I notice there are some gems and libs that have been vendored into the project but can't tell if they are being used or what! How can I workout if some of those gems are no longer being used by the project?