Module: ConfigManager::Settings::Persistence::ClassMethods

Defined in:
lib/config_manager/settings/persistence.rb

Instance Method Summary collapse

Instance Method Details

#build(params) ⇒ Object



13
14
15
16
17
18
# File 'lib/config_manager/settings/persistence.rb', line 13

def build(params)
	tags = (params[:tags] || params[:formatted_tags] || "").
			gsub(/\s*,\s*/,',').
			split(',')
	new(params[:id], params[:value], tags)
end

#create(params) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/config_manager/settings/persistence.rb', line 20

def create(params)
	setting = build(params)
	if setting.valid?
		setting.persist
		find(params[:id], true)
	else
		setting
	end
end

#delete(id) ⇒ Object



43
44
45
# File 'lib/config_manager/settings/persistence.rb', line 43

def delete(id)
	$redis.del(generate_key(id), generate_tags_key(id))
end

#persist(id, value, *indexes) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/config_manager/settings/persistence.rb', line 30

def persist(id, value, *indexes)
	$redis.set(generate_key(id), value)
	unless indexes.empty?
		$redis.sadd(generate_tags_key(id), indexes) 
		$redis.sadd(tag_global_key, indexes)
	end
	
	# update global and tag indexes
	indexes = indexes.map{|index| generate_index(index)}
	indexes << global_key
	index_by(id, indexes)
end