Module: Uber::Builder::ClassMethods
- Defined in:
- lib/uber/builder.rb
Instance Method Summary collapse
-
#builds(&block) ⇒ Object
Adds a builder to the cell class.
- #class_builder ⇒ Object
Instance Method Details
#builds(&block) ⇒ Object
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, |
AuthorizedUserBox if [:is_signed_in]
AdminUserBox if model.admin?
end
In your view #cell will instantiate the right cell for you now.
82 83 84 |
# File 'lib/uber/builder.rb', line 82 def builds(&block) builders << block end |