Sha256: 39d81a129f1f863aff07d78fbc37b1bc3361c788c9f2f48dddce829b0a675da4
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
# encoding: UTF-8 # # Copyright 2011 Brennan Frydl (http://bfrydl.com/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. module Settis module Container # @private def redis @redis ||= Redis::Namespace.new(namespace, :redis => Settis.redis) end # @overload namespace(value) # Sets the namespace prefix to be added before all Redis key names. # @param [String] value The prefix to add. # @overload namespace # Gets the namespace prefix to be added before all Redis key names. def namespace(value = nil) if value.nil? @namespace ||= 'settings' else @namespace = value end end # Defines a new setting. # # @param [Symbol, String] name The name of the setting. # @param [Symbol, Class] type The type of the setting. # @param [Hash] options # @option options :default The default value of the setting. Not supported for lists, sets, and hashes. def setting(name, type, options = {}) @settings ||= {} name = name.to_s raise ArgumentError, "The setting '#{name}' already exists." if @settings.key?(name) serializer = Serializer.for(type) raise ArgumentError, "Unknown setting type '#{type}'." if serializer.nil? @settings[name] = ScalarSetting.new(self, name, serializer.new(type), options) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
settis-0.2.0 | lib/settis/container.rb |