Class: Settis::Setting
- Inherits:
-
Object
- Object
- Settis::Setting
- Defined in:
- lib/settis/setting.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(container, name, options = {}) ⇒ Setting
constructor
A new instance of Setting.
- #set(value) ⇒ Object
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, = {}) @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
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/settis/setting.rb', line 19 def name @name end |
Instance Method Details
#get ⇒ Object
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 |