class PleaseRun::Configurable::FacetDSL

A DSL for describing a facet.

For example:

Facet.new(:temperature, "The temperature value") do
  validate do |v|
    fail "Temperature must be a number" unless v.is_a?(Numeric)
  end
  munge do |v|
    Float(v)
  end
end

Both validation and munge blocks are optional.

The 'validate' block is expcted to fail if the value given to the facet is not valid.

The 'munge' block is intended to help you coerce a value. For example, if you take “1234” from the user input (for example, as a command line flag value), you could use 'munge' to convert it to a number, as above.

Munge is invoked before validation. Munge can fail if an invalid value is given.

Public Class Methods

new(facet, &block) click to toggle source
# File lib/pleaserun/configurable.rb, line 121
def initialize(facet, &block)
  @facet = facet
  instance_eval(&block)
end

Public Instance Methods

munge(&block) click to toggle source
# File lib/pleaserun/configurable.rb, line 130
def munge(&block)
  @facet.munger = block
end
validate(&block) click to toggle source
# File lib/pleaserun/configurable.rb, line 126
def validate(&block)
  @facet.validator = block
end