Module: Kasket

Defined in:
lib/kasket.rb,
lib/kasket/version.rb,
lib/kasket/visitor.rb,
lib/kasket/read_mixin.rb,
lib/kasket/dirty_mixin.rb,
lib/kasket/write_mixin.rb,
lib/kasket/query_parser.rb,
lib/kasket/relation_mixin.rb,
lib/kasket/configuration_mixin.rb,
lib/kasket/select_manager_mixin.rb,
lib/kasket/reload_association_mixin.rb

Defined Under Namespace

Modules: ConfigurationMixin, DirtyMixin, ReadMixin, RelationMixin, ReloadAssociationMixin, SelectManagerMixin, WriteMixin Classes: QueryParser, Version, Visitor

Constant Summary collapse

AR30 =
(ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0)
CONFIGURATION =
{:max_collection_size => 100}

Class Method Summary collapse

Class Method Details

.cacheObject



50
51
52
# File 'lib/kasket.rb', line 50

def self.cache
  @cache_store ||= Rails.cache
end

.cache_store=(options) ⇒ Object



46
47
48
# File 'lib/kasket.rb', line 46

def self.cache_store=(options)
  @cache_store = ActiveSupport::Cache.lookup_store(options)
end

.clear_localObject



54
55
56
57
58
# File 'lib/kasket.rb', line 54

def clear_local
  if Kasket.cache.respond_to?(:with_local_cache)
    Kasket.cache.send(:local_cache).try(:clear)
  end
end

.setup(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kasket.rb', line 25

def setup(options = {})
  return if ActiveRecord::Base.respond_to?(:has_kasket)

  CONFIGURATION[:max_collection_size] = options[:max_collection_size] if options[:max_collection_size]

  ActiveRecord::Base.extend(Kasket::ConfigurationMixin)

  if defined?(ActiveRecord::Relation)
    ActiveRecord::Relation.send(:include, Kasket::RelationMixin)
    Arel::SelectManager.send(:include, Kasket::SelectManagerMixin)
  end

  if options[:assoliations_reload_hack]
    ActiveRecord::Associations::BelongsToAssociation.send(:include, Kasket::ReloadAssociationMixin)
    if ActiveRecord::VERSION::MAJOR == 2 || AR30
      ActiveRecord::Associations::BelongsToPolymorphicAssociation.send(:include, Kasket::ReloadAssociationMixin)
    end
    ActiveRecord::Associations::HasOneThroughAssociation.send(:include, Kasket::ReloadAssociationMixin)
  end
end