Class: WhoIsOnline::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/whoisonline/configuration.rb

Constant Summary collapse

DEFAULT_NAMESPACE =
"whoisonline:user".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
19
20
# File 'lib/whoisonline/configuration.rb', line 11

def initialize
  @ttl = 5.minutes
  @throttle = 60.seconds
  @user_id_method = :id
  @current_user_method = :current_user
  @namespace = DEFAULT_NAMESPACE
  @auto_hook = true
  @logger = default_logger
  @heartbeat_interval = 60.seconds
end

Instance Attribute Details

#auto_hookObject

Returns the value of attribute auto_hook.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def auto_hook
  @auto_hook
end

#current_user_methodObject

Returns the value of attribute current_user_method.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def current_user_method
  @current_user_method
end

#heartbeat_intervalObject

Returns the value of attribute heartbeat_interval.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def heartbeat_interval
  @heartbeat_interval
end

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def logger
  @logger
end

#namespaceObject

Returns the value of attribute namespace.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def namespace
  @namespace
end

#redisObject



22
23
24
25
26
# File 'lib/whoisonline/configuration.rb', line 22

def redis
  @redis ||= lambda do
    Redis.new(url: ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379/0"))
  end
end

#throttleObject

Returns the value of attribute throttle.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def throttle
  @throttle
end

#ttlObject

Returns the value of attribute ttl.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def ttl
  @ttl
end

#user_id_methodObject

Returns the value of attribute user_id_method.



7
8
9
# File 'lib/whoisonline/configuration.rb', line 7

def user_id_method
  @user_id_method
end

Instance Method Details

#redis_connectionObject

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File 'lib/whoisonline/configuration.rb', line 28

def redis_connection
  client = redis.respond_to?(:call) ? redis.call : redis
  raise ArgumentError, "config.redis must return a Redis-compatible client" unless client.respond_to?(:set)

  client
end