Class Settings::Setting
In: lib/more/facets/settings.rb
Parent: Object

A datastructure to store Settings metadata.

Please note the difference between :default and :value, :default does NOT override :value.

Methods

new   to_s   update  

Attributes

name  [RW] 
options  [RW] 
owner  [RW] 
type  [RW] 
value  [RW] 

Public Class methods

[Source]

# File lib/more/facets/settings.rb, line 66
    def initialize(owner, name, options)
      if options.key? :value
        @value = options[:value]
      elsif options.key? :default
        @value = options[:default]
      else
        raise ArgumentError.new('A value is required')
      end

      @owner, @name = owner, name
      @options = options
      @type = options[:type] = options[:type] || @value.class
    end

Public Instance methods

Text representation of this setting.

[Source]

# File lib/more/facets/settings.rb, line 98
    def to_s
      @value.to_s
    end

Update the setting from an options hash. The update does NOT take default values into account!

[Source]

# File lib/more/facets/settings.rb, line 83
    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

[Validate]