Sha256: 01850d5584b2fb3f526347120c793db1404ef5305a18d2f20db4126a0558c1d3

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 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)
  	  	  around_filter :with_identity_map, *args
  	  	end
  	  	
  	  	def dont_use_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
else
  ActionController::Dispatcher.send :include, DispatcherMethods
end

Version data entries

1 entries across 1 versions & 1 rubygems

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