Class: Morlock::MorlockRailtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/morlock/rails.rb

Class Method Summary collapse

Class Method Details

.detect_memcache_gemObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/morlock/rails.rb', line 34

def self.detect_memcache_gem
  if defined?(ActiveSupport::Cache::MemCacheStore) && Rails.cache.is_a?(ActiveSupport::Cache::MemCacheStore)
    setup_for_mem_cache_store
  elsif defined?(ActiveSupport::Cache::DalliStore) && Rails.cache.is_a?(ActiveSupport::Cache::DalliStore)
    setup_for_dalli_store
  elsif Rails.env.test?
    setup_for_test_store
  else
    Rails.logger.warn "WARNING: Morlock detected that you are not using the Rails ActiveSupport::Cache::MemCacheStore.  Rails.morlock will not be setup."
  end
end

.setup_for_dalli_storeObject



20
21
22
# File 'lib/morlock/rails.rb', line 20

def self.setup_for_dalli_store
  self.setup_for_mem_cache_store
end

.setup_for_mem_cache_storeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/morlock/rails.rb', line 6

def self.setup_for_mem_cache_store
  if Rails.cache.instance_variable_get(:@data)
    Rails.module_eval do
      class << self
        def morlock
          @@morlock ||= Morlock.new(Rails.cache.instance_variable_get(:@data))
        end
      end
    end
  else
    Rails.logger.warn "WARNING: Morlock could not load @data in #setup_for_mem_cache_store.  Perhaps we don't yet work with this version of Rails?"
  end
end

.setup_for_test_storeObject



24
25
26
27
28
29
30
31
32
# File 'lib/morlock/rails.rb', line 24

def self.setup_for_test_store
  Rails.module_eval do
    class << self
      def morlock
        @@morlock ||= Morlock.new(:test)
      end
    end
  end
end