Class: Settis::Setting

Inherits:
Object
  • Object
show all
Defined in:
lib/settis/setting.rb

Direct Known Subclasses

ScalarSetting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, name, options = {}) ⇒ Setting

Returns a new instance of Setting.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/settis/setting.rb', line 22

def initialize(container, name, options = {})
  @container = container
  @name = name

  class << container ; self ; end.instance_exec(self) do |this|
    define_method name do
      this.get
    end

    define_method :"#{name}=" do |value|
      this.set(value)
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/settis/setting.rb', line 19

def name
  @name
end

Instance Method Details

#getObject



37
38
39
# File 'lib/settis/setting.rb', line 37

def get
  @container.redis.get(name)
end

#set(value) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/settis/setting.rb', line 41

def set(value)
  if value.nil?
    @container.redis.del(name)
  else
    @container.redis.set(name, value)
  end

  value
end