module Uber::Builder

When included, allows to add builder on the class level.

class Operation
  include Uber::Builder

  builds do |params|
    SignedIn if params[:current_user]
  end

  class SignedIn
  end

The class then has to call the builder to compute a class name using the build blocks you defined.

def self.build(params)
  class_builder.call(params).
  new(params)
end

Public Class Methods

builders() click to toggle source
# File lib/uber/builder.rb, line 25
def self.builders
  @builders ||= []
end
included(base) click to toggle source
# File lib/uber/builder.rb, line 23
def self.included(base)
  base.class_eval do
    def self.builders
      @builders ||= []
    end

    extend ClassMethods
  end
end