Module: Gamera::Builder::Dsl

Included in:
Gamera::Builder
Defined in:
lib/gamera/builder.rb

Overview

Module to extend the Builder DSL

Instance Method Summary collapse

Instance Method Details

#default_for(option_name, val = nil, &gen) ⇒ Object

Sets the default value of an option

Yields self to block (gen) if a block is provided. Return value will be the default value.

Parameters:

  • option_name (String)

    Name of the builder option

  • val (Object) (defaults to: nil)

    the simple default value of the option

  • gen (Block)

    block that returns default values


149
150
151
152
153
154
155
156
157
# File 'lib/gamera/builder.rb', line 149

def default_for(option_name, val = nil, &gen)
  gen ||= ->(_) { val }

  prepend(Module.new do
    define_method :"#{option_name}_coercion" do |v|
      super v.nil? ? gen.call(self) : v
    end
  end)
end