Module: Kasket
- Defined in:
- lib/kasket.rb,
lib/kasket/cache.rb,
lib/kasket/read_mixin.rb,
lib/kasket/dirty_mixin.rb,
lib/kasket/write_mixin.rb,
lib/kasket/query_parser.rb,
lib/kasket/rack_middleware.rb,
lib/kasket/configuration_mixin.rb,
lib/kasket/active_record_patches.rb,
lib/kasket/reload_association_mixin.rb
Defined Under Namespace
Modules: ConfigurationMixin, DirtyMixin, FixForAssociationAccessorMethods, ReadMixin, ReloadAssociationMixin, WriteMixin
Classes: Cache, QueryParser, RackMiddleware, Version
Constant Summary
collapse
- CONFIGURATION =
{:max_collection_size => 100}
Class Method Summary
collapse
Class Method Details
.cache ⇒ Object
25
26
27
|
# File 'lib/kasket.rb', line 25
def cache
Thread.current["kasket_cache"] ||= Cache.new
end
|
.setup(options = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/kasket.rb', line 29
def setup(options = {})
CONFIGURATION[:max_collection_size] = options[:max_collection_size] if options[:max_collection_size]
ActiveRecord::Base.extend(Kasket::ConfigurationMixin)
ActiveRecord::Associations::BelongsToAssociation.send(:include, Kasket::ReloadAssociationMixin)
ActiveRecord::Associations::BelongsToPolymorphicAssociation.send(:include, Kasket::ReloadAssociationMixin)
ActiveRecord::Associations::HasOneThroughAssociation.send(:include, Kasket::ReloadAssociationMixin)
begin
ApplicationController.before_filter do
Kasket.cache.clear_local
end
rescue NameError => e
puts('WARNING: The kasket before filter did not register (this is OK in the test environment)')
end
begin
ActionController::Dispatcher.middleware.use(Kasket::RackMiddleware)
rescue NameError => e
puts('WARNING: The kasket rack middleware is not in your rack stack (this is OK in the test environment)')
end
begin
ActiveSupport::TestCase.class_eval do
setup :clear_cache
def clear_cache
Kasket.cache.clear_local
Rails.cache.clear if Rails.cache.respond_to?(:clear)
end
end
rescue NameError => e
end
end
|