module Gamera::Builder::Dsl

Module to extend the Builder DSL

Public Instance Methods

default_for(option_name, val = nil, &gen) click to toggle source

Sets the default value of an option

@param option_name [String] Name of the builder option @param val [Object] the simple default value of the option @param gen [Block] block that returns default values

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

Calls superclass method
# 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