Sha256: 52f8f4bf9b154630740a3acb9c1989b0a474a994dec2bbaaba0167972e090174

Contents?: true

Size: 1.11 KB

Versions: 45

Compression:

Stored size: 1.11 KB

Contents

module CouchPotato
  
  module ClassReloading
    private
    
    def with_class_reloading(&block)
      begin
        yield
      rescue ArgumentError => e
        if(name = e.message.scan(/(can't find const|undefined class\/module) ([\w\:]+)/).try(:first).try(:[], 1))
          eval name.gsub(/\:+$/, '')
          retry
        else
          raise e
        end
      end
    end
  end
  
  View::ViewQuery.class_eval do
    include ClassReloading

    def query_view_with_class_reloading(*args)
      with_class_reloading do
        query_view_without_class_reloading(*args)
      end
    end

    alias_method :query_view_without_class_reloading, :query_view
    alias_method :query_view, :query_view_with_class_reloading
  end
  
  Database.class_eval do
    include ClassReloading

    def load_document_with_class_reloading(*args)
      with_class_reloading do
        load_document_without_class_reloading *args
      end
    end

    alias_method :load_document_without_class_reloading, :load_document
    alias_method :load_document, :load_document_with_class_reloading
    alias_method :load, :load_document
  end
end

Version data entries

45 entries across 45 versions & 3 rubygems

Version Path
couch_potato-1.18.0 rails/reload_classes.rb
couch_potato-1.17.0 rails/reload_classes.rb
couch_potato-1.16.0 rails/reload_classes.rb
couch_potato-1.15.0 rails/reload_classes.rb
couch_potato-1.14.0 rails/reload_classes.rb
couch_potato-1.13.0 rails/reload_classes.rb
couch_potato-1.12.1 rails/reload_classes.rb
couch_potato-1.12.0 rails/reload_classes.rb
couch_potato-1.11.0 rails/reload_classes.rb
couch_potato-1.10.1 rails/reload_classes.rb
couch_potato-1.10.0 rails/reload_classes.rb
couch_potato-1.9.0 rails/reload_classes.rb
couch_potato-1.7.1 rails/reload_classes.rb
couch_potato-1.7.0 rails/reload_classes.rb
couch_potato-1.6.5 rails/reload_classes.rb
couch_potato-1.6.4 rails/reload_classes.rb
couch_potato-1.6.3 rails/reload_classes.rb
couch_potato-1.4.0 rails/reload_classes.rb
couch_potato-1.3.0 rails/reload_classes.rb
couch_potato-1.2.0 rails/reload_classes.rb