Class: Settings::Setting
Overview
A datastructure to store Settings metadata.
Please note the difference between :default and :value, :default does NOT override :value.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(owner, name, options) ⇒ Setting
constructor
A new instance of Setting.
-
#to_s ⇒ Object
Text representation of this setting.
-
#update(hash) ⇒ Object
Update the setting from an options hash.
Constructor Details
#initialize(owner, name, options) ⇒ Setting
Returns a new instance of Setting.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/more/facets/settings.rb', line 68 def initialize(owner, name, ) if .key? :value @value = [:value] elsif .key? :default @value = [:default] else raise ArgumentError.new('A value is required') end @owner, @name = owner, name @options = @type = [:type] = [:type] || @value.class end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
66 67 68 |
# File 'lib/more/facets/settings.rb', line 66 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
66 67 68 |
# File 'lib/more/facets/settings.rb', line 66 def @options end |
#owner ⇒ Object
Returns the value of attribute owner.
66 67 68 |
# File 'lib/more/facets/settings.rb', line 66 def owner @owner end |
#type ⇒ Object
Returns the value of attribute type.
66 67 68 |
# File 'lib/more/facets/settings.rb', line 66 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
66 67 68 |
# File 'lib/more/facets/settings.rb', line 66 def value @value end |
Instance Method Details
#to_s ⇒ Object
Text representation of this setting.
100 101 102 |
# File 'lib/more/facets/settings.rb', line 100 def to_s @value.to_s end |
#update(hash) ⇒ Object
Update the setting from an options hash. The update does NOT take default values into account!
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/more/facets/settings.rb', line 85 def update(hash) if hash.key? :value @value = hash[:value] @type = @value.class end if hash.key? :type @type = hash[:type] end @options.update(hash) end |