Class: DeviseCasAuthenticatable::MemcacheChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_cas_authenticatable/memcache_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rails_configuration) ⇒ MemcacheChecker

Returns a new instance of MemcacheChecker.


8
9
10
# File 'lib/devise_cas_authenticatable/memcache_checker.rb', line 8

def initialize(rails_configuration)
  @rails_configuration = rails_configuration
end

Instance Attribute Details

#rails_configurationObject (readonly)

Returns the value of attribute rails_configuration


6
7
8
# File 'lib/devise_cas_authenticatable/memcache_checker.rb', line 6

def rails_configuration
  @rails_configuration
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)

16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/devise_cas_authenticatable/memcache_checker.rb', line 16

def alive?
  memcache_servers = rails_configuration.session_options[:memcache_server] || ["127.0.0.1:11211"]
  memcache_servers.each do |server|
    host, port = server.split(":")
    begin
      try_connect host, port

      return true
    rescue Errno::ECONNREFUSED, Timeout::Error
      return false
    end
  end
end

#session_store_memcache?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'lib/devise_cas_authenticatable/memcache_checker.rb', line 12

def session_store_memcache?
  !!(session_store_class.name =~ /memcache/i)
end

#try_connect(host, port) ⇒ Object


30
31
32
33
34
# File 'lib/devise_cas_authenticatable/memcache_checker.rb', line 30

def try_connect(host, port)
  Timeout::timeout(1) do
    TCPSocket.open(host, port)
  end
end