Module: Settis::Container

Defined in:
lib/settis/container.rb

Instance Method Summary collapse

Instance Method Details

#namespace(value) ⇒ Object #namespaceObject

Overloads:

  • #namespace(value) ⇒ Object

    Sets the namespace prefix to be added before all Redis key names.

    Parameters:

    • value (String)

      The prefix to add.

  • #namespaceObject

    Gets the namespace prefix to be added before all Redis key names.



29
30
31
32
33
34
35
# File 'lib/settis/container.rb', line 29

def namespace(value = nil)
  if value.nil?
    @namespace ||= 'settings'
  else
    @namespace = value
  end
end

#redisObject



20
21
22
# File 'lib/settis/container.rb', line 20

def redis
  @redis ||= Redis::Namespace.new(namespace, :redis => Settis.redis)
end

#setting(name, type, options = {}) ⇒ Object

Defines a new setting.

Parameters:

  • name (Symbol, String)

    The name of the setting.

  • type (Symbol, Class)

    The type of the setting.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :default (Object)

    The default value of the setting. Not supported for lists, sets, and hashes.

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/settis/container.rb', line 43

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