Sha256: 73b10957d5a5071a6e729ab66f423d27639ae318c06d42e6384e1043125c8fb8

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require "morlock/version"
require 'morlock/base'

class Morlock
  class MorlockRailtie < ::Rails::Railtie
    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
      end
    end

    def self.setup_for_dalli_store
      self.setup_for_mem_cache_store
    end

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

    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

    config.after_initialize do
      detect_memcache_gem
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
morlock-0.0.4 lib/morlock/rails.rb