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

CONFIGURATION =
{:max_collection_size => 100}

Class Method Summary collapse

Class Method Details

.cacheObject



44
45
46
# File 'lib/kasket.rb', line 44

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

.cache_store=(options) ⇒ Object



40
41
42
# File 'lib/kasket.rb', line 40

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

.clear_localObject



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

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

.setup(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kasket.rb', line 22

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)
    ActiveRecord::Associations::HasOneThroughAssociation.send(:include, Kasket::ReloadAssociationMixin)
  end
end