Module: Frivol::Config

Defined in:
lib/frivol/config.rb

Overview

Frivol::Config

Sets the Frivol configuration (currently only the Redis config), allows access to the configured Redis instance, and has a helper method to include Frivol in a class with an optional storage expiry parameter

Class Method Summary collapse

Class Method Details

.allow_json_createObject



33
34
35
# File 'lib/frivol/config.rb', line 33

def self.allow_json_create
  @@allow_json_create ||= []
end

.include_in(host_class, storage_expires_in = nil) ⇒ Object

A convenience method to include Frivol in a class, with an optional storage expiry parameter.

For example, you might have the following in environment.rb:

Frivol::Config.redis_config = REDIS_CONFIG
Frivol::Config.include_in ActiveRecord::Base, 600

Which would include Frivol in ActiveRecord::Base and set the default storage expiry to 10 minutes



43
44
45
46
# File 'lib/frivol/config.rb', line 43

def self.include_in(host_class, storage_expires_in = nil)
  host_class.send(:include, Frivol)
  host_class.storage_expires_in storage_expires_in if storage_expires_in
end

.redisObject

Returns the configured Redis instance



21
22
23
# File 'lib/frivol/config.rb', line 21

def self.redis
  Thread.current[:frivol_redis] ||= Redis.new(@@redis_config)
end

.redis_config=(config) ⇒ Object

Set the Redis configuration.

Expects a hash such as

REDIS_CONFIG = {
  :host => "localhost",
  :port => 6379
}
Frivol::Config.redis_config = REDIS_CONFIG


14
15
16
17
18
# File 'lib/frivol/config.rb', line 14

def self.redis_config=(config)
  @@redis_config = config
  @@redis_version = nil
  Thread.current[:frivol_redis] = nil
end

.redis_versionObject



25
26
27
# File 'lib/frivol/config.rb', line 25

def self.redis_version
  redis.info('server')['redis_version'].to_f
end

.requires_expiry_reset?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/frivol/config.rb', line 29

def self.requires_expiry_reset?
  redis_version < 2.2
end