Sha256: b8ae8fe1493e41d0d05fe180348afced2831bb01b87bea8f7a8f8777b1ea5266

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module ActionController
  class Base
  	module IdentityMap
  	  module InstanceMethods
		def with_identity_map
		  ActiveRecord::Base.with_id_map {
			yield
		  }
		end
		
		def without_identity_map
		  ActiveRecord::Base.without_id_map {
			yield
		  }
		end
	  end
  	  
  	  module ClassMethods
  	  	def use_identity_map(*args)
  	  	  skip_around_filter :without_identity_map, *args
  	  	  around_filter :with_identity_map, *args
  	  	end
  	  	
  	  	def dont_use_identity_map(*args)
  	  	  skip_around_filter :with_identity_map, *args
  	  	  around_filter :without_identity_map, *args
  	  	end
  	  	
  	  	def use_dispater_identity_map
  	  	  if defined? ::ActionDispatch
  	  	  	ActionDispatch::Callbacks.before :create_identity_map
  	  	  	ActionDispatch::Callbacks.after :remove_identity_map
  	  	  else
  	  	  	ActionController::Dispatcher.before_dispatch :create_identity_map
  	  	  	ActionController::Dispatcher.after_dispatch :remove_identity_map
  	  	  end
  	  	end
  	  end
  	  

  	end
  	extend IdentityMap::ClassMethods
  	include IdentityMap::InstanceMethods
  end
end

module DispatcherMethods
  def create_identity_map
	ActiveRecord::Base.create_identity_map
  end
  
  def remove_identity_map
	ActiveRecord::Base.drop_identity_map
  end
end

if defined? ::ActionDispatch
  ActionDispatch::Callbacks.send :include, DispatcherMethods
  RAILS_DEFAULT_LOGGER.warn "CACHING OBJECTS"
else
  ActionController::Dispatcher.send :include, DispatcherMethods
  RAILS_DEFAULT_LOGGER.warn "CACHING OBJECTS"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ar-simple-idmap-0.1.1 lib/identity_map/action_controller/dispatcher.rb
ar-simple-idmap-0.1.0 lib/identity_map/action_controller/dispatcher.rb