class PleaseRun::Configurable::Facet
A generalized facet/property/container for a single value.
Supports naming and text descriptions of this thing.
Also supports value validation and munging on assignment to help you more easily accept user input from a variety of sources and keep the validation and value munging concerns near the value itself.
Attributes
Public Class Methods
Source
# File lib/pleaserun/configurable.rb, line 148 def initialize(name, description, options = {}, &facet_dsl) insist { name }.is_a?(Symbol) insist { description }.is_a?(String) insist { options }.is_a?(Hash) @name = name @description = description @options = options FacetDSL.new(self, &facet_dsl) if block_given? validate(@options[:default]) if @options[:default] end
Public Instance Methods
Source
# File lib/pleaserun/configurable.rb, line 168 def validate(v) return @validator.call(v) if @validator rescue => e raise ValidationError, "Invalid value '#{v.inspect}' for attribute '#{name}' (#{e})" end
Source
# File lib/pleaserun/configurable.rb, line 174 def value return @value if @value return @options[:default] if @options.include?(:default) return nil end
Source
# File lib/pleaserun/configurable.rb, line 162 def value=(v) v = @munger.call(v) if @munger validate(v) @value = v end