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

Defined Under Namespace

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

Constant Summary collapse

CONFIGURATION =

rubocop:disable Style/MutableConstant

{ # rubocop:disable Style/MutableConstant
  max_collection_size: 100,
  write_through: false,
  default_expires_in: nil
}
VERSION =
'4.10.4'

Class Method Summary collapse

Class Method Details

.add_pending_record(record, destroyed = false) ⇒ Object



60
61
62
63
# File 'lib/kasket.rb', line 60

def self.add_pending_record(record, destroyed = false)
  Thread.current[:kasket_pending_records] ||= {}
  Thread.current[:kasket_pending_records][record] = destroyed ? nil : record
end

.cache_storeObject Also known as: cache



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

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

.cache_store=(options) ⇒ Object



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

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

.clear_pending_recordsObject



65
66
67
# File 'lib/kasket.rb', line 65

def self.clear_pending_records
  Thread.current[:kasket_pending_records] = nil
end

.pending_recordsObject

Keys are the records being saved. Values are either the saved record, or nil if the record has been destroyed.



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

def self.pending_records
  Thread.current[:kasket_pending_records]
end

.setup(options = {}) ⇒ Object



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

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

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

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

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