class Yaks::Builder
State monad-ish thing.
Generate a DSL syntax for immutable classes.
@example
# This code Form.create(:search) .method("POST") .action("/search") # Can be written as Builder.new(Form, [:method, :action]).create(:search) do method "POST" action "/search" end
Public Class Methods
new(klass, methods = [], &block)
click to toggle source
# File lib/yaks/builder.rb, line 22 def initialize(klass, methods = [], &block) @klass = klass @methods = methods def_forward(*methods) if methods.any? instance_eval(&block) if block end
Public Instance Methods
build(init_state, *extra_args, &block)
click to toggle source
# File lib/yaks/builder.rb, line 33 def build(init_state, *extra_args, &block) @config = init_state instance_exec(*extra_args, &block) if block @config end
create(*args, &block)
click to toggle source
# File lib/yaks/builder.rb, line 29 def create(*args, &block) build(@klass.create(*args), &block) end
inspect()
click to toggle source
# File lib/yaks/builder.rb, line 39 def inspect "#<Builder #{@klass} #{@methods}>" end