lib/require_reloader.rb
# Reload a specific gem or a gem-like .rb file
# automatically on each request.
#
# In Rails 3.2+, reload happens only when a watchable file is modified.
#
# To use it, add 'RequireReloader.watch :my_gem' to
# your config/environments/development.rb.
#
Reload a specific gem or a gem-like .rb file
automatically on each request.

In Rails 3.2+, reload happens only when a watchable file is modified.


Reload a specific gem or a gem - like . rb file automatically on each request . In Rails 3 . 2 + reload happens only when a watchable file is modified .
def watch(gem_name, opts={})
      gem            = gem_name.to_s
      watchable_dir  = expanded_gem_path(gem, opts[:path])
      watchable_exts = opts[:exts] ? Array(opts[:exts]) : [:rb]
      helper         = Helper.new
      app = Object.const_get(Rails.application.class.parent_name)
      app::Application.configure do
        if watchable_dir && config.respond_to?(:watchable_dirs)
          config.watchable_dirs[watchable_dir] = watchable_exts
        end
        helper.to_prepare do
          if opts[:module_name]
            helper.remove_module_if_defined(opts[:module_name])
          else
            helper.remove_gem_module_if_defined(gem)
          end
          $".delete_if {|s| s.include?(gem)}
          require gem
          opts[:callback].call(gem) if opts[:callback]
        end
      end
    end
def watch ( gem_name , opts = { } ) gem = gem_name . to_s watchable_dir = expanded_gem_path ( gem , opts [ :path ] ) watchable_exts = opts [ :exts ] ? Array ( opts [ :exts ] ) : [ :rb ] helper = Helper . new app = Object . const_get ( Rails . application . class . parent_name ) app :: Application . configure do if watchable_dir && config . respond_to? ( :watchable_dirs ) config . watchable_dirs [ watchable_dir ] = watchable_exts end helper . to_prepare do if opts [ :module_name ] helper . remove_module_if_defined ( opts [ :module_name ] ) else helper . remove_gem_module_if_defined ( gem ) end $" . delete_if { | s | s . include? ( gem ) } require gem opts [ :callback ] . call ( gem ) if opts [ :callback ] end end end
Reload a specific gem or a gem-like .rb file
automatically on each request.
Reload a specific gem or a gem - like . rb file automatically on each request .
# based on Tim Cardenas's solution: # http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
gem_name
opts