Sha256: 3cf830d04b964c766f6399dcf723f7fc16dfa54c1d03826974b87cd3909f58c5

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

module ConfigManager
	class Setting
		include Settings::Persistence
		include Settings::Querying
		include Settings::Values
		include Settings::Yaml

		attr_reader :id, :value, :tags

		def initialize(id, value, tags)
			@id = id
			@value = value
			@tags = tags
		end	

		def valid?
			@id.present? && !!@value
		end

		def formatted_tags
			@tags && @tags.join(', ')
		end

		def message
			return "missing name(id)" unless @id.present?
			return "missing value" unless !!@value
		end

		def to_hash
			{'id' => id, 'value' => value, 'tags' => formatted_tags}
		end

		class << self
		private
			def generate_key(id)
				"#{prefix}:#{id}"
			end

			def generate_tags_key(id)
				"#{prefix}_tags:#{id}"
			end

			def generate_index(id)
				"#{prefix}_index:#{id}"
			end

			def global_key
				"#{prefix}_global"
			end

			def tag_global_key
				"#{prefix}_tags_index"
			end

			def prefix
				"#{Rails.application.class.parent_name.underscore}_cm_settings"
			end

			def store_key_by_index(index, key)
				$redis.sadd(index, generate_key(key))
			end
		end
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
config_manager-1.0.4 lib/config_manager/setting.rb
config_manager-1.0.3 lib/config_manager/setting.rb
config_manager-1.0.2 lib/config_manager/setting.rb
config_manager-1.0.0 lib/config_manager/setting.rb
config_manager-0.0.10 lib/config_manager/setting.rb