Module: Vissen::Parameterized::DSL

Defined in:
lib/vissen/parameterized/dsl.rb

Overview

This module provides a DSL for defining input parameters and output values for parameterized objects.

Usage

class Example
  extend DSL

  param input:  Value::Vec,
        offset: Value::Real
end

Instance Method Summary collapse

Instance Method Details

#class_outputValue?

Returns a new instance of the value class defined using ‘#output`, or nil if nothing was defined.

Returns:

  • (Value, nil)

    a new instance of the value class defined using ‘#output`, or nil if nothing was defined.

Raises:

  • (RuntimeError)

    if no output class has been defined.



48
49
50
51
# File 'lib/vissen/parameterized/dsl.rb', line 48

def class_output
  return nil unless defined? @_output
  @_output.new
end

#class_parametersHash<Symbol, Parameter>

Returns a new hash containing one parameter object for each parameter key.

Returns:

  • (Hash<Symbol, Parameter>)

    a new hash containing one parameter object for each parameter key.



37
38
39
40
41
42
# File 'lib/vissen/parameterized/dsl.rb', line 37

def class_parameters
  return {}.freeze unless defined? @_params

  @_params.each_with_object({}) { |(k, v), h| h[k] = Parameter.new(*v) }
          .freeze
end

#output(value_klass) ⇒ nil

Parameters:

  • value_klass (Class)

    the value class to use.

Returns:

  • (nil)


30
31
32
33
# File 'lib/vissen/parameterized/dsl.rb', line 30

def output(value_klass)
  @_output = value_klass
  nil
end

#param(key, value_klass, default: nil) ⇒ nil

Parameters:

  • key (Symbol)

    the parameter to add.

  • value_klass (Class)

    the value type of the parameter.

  • default (Object) (defaults to: nil)

    the default value of the parameter.

Returns:

  • (nil)


22
23
24
25
26
# File 'lib/vissen/parameterized/dsl.rb', line 22

def param(key, value_klass, default: nil)
  @_params = {} unless defined? @_params
  @_params[key] = [value_klass, default].freeze
  nil
end