module Uber::Builder::ClassMethods

Public Instance Methods

builds(proc=nil, &block) click to toggle source

Adds a builder to the cell class. Builders are used in cell to find out the concrete class for rendering. This is helpful if you frequently want to render subclasses according to different circumstances (e.g. login situations) and you don’t want to place these deciders in your view code.

Passes the model and options from cell into the block.

Multiple build blocks are ORed, if no builder matches the building cell is used.

Example:

Consider two different user box cells in your app.

class AuthorizedUserBox < UserInfoBox
end

class AdminUserBox < UserInfoBox
end

Now you don’t want to have deciders all over your views - use a declarative builder.

UserInfoBox.build do |model, options|
  AuthorizedUserBox if options[:is_signed_in]
  AdminUserBox if model.admin?
end

In your view cell will instantiate the right cell for you now.

# File lib/garcon/utility/uber/builder.rb, line 82
def builds(proc=nil, &block)
  builders << (proc.kind_of?(Proc) ? proc : block)
end
class_builder() click to toggle source
# File lib/garcon/utility/uber/builder.rb, line 86
def class_builder
  @class_builder ||= Constant.new(self)
end