Class: ConConfig

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/con_config.rb

Class Method Summary collapse

Class Method Details

.get(key) ⇒ String

Returns value of the given key, or raises ConfigNotFound

Examples:

Get the value of a key

ConConfig.get('key')

Raises:


21
22
23
24
25
# File 'app/models/con_config.rb', line 21

def self.get(key)
	raise ConfigNotFound, 'key must not be empty' unless key.present?

	get_value(key)
end

.multi_set(keys) ⇒ nil

Sets multiple keys at once

Examples:

Set two elements

ConConfig.multi_set(a: 1, b: 2)

See Also:


38
39
40
41
42
# File 'app/models/con_config.rb', line 38

def self.multi_set(keys)
	keys.each do |key, value|
		set(key, value)
	end
end

.set(key, value) ⇒ Object

Sets the value of the given key

Examples:

Set the value of a key

ConConfig.set('key', 'value')

55
56
57
58
59
# File 'app/models/con_config.rb', line 55

def self.set(key, value)
	config = ConConfig.where(key: key).first_or_initialize
	config.update_attribute(:value, value)
	set_in_redis(key, value)
end