Build up objects close to where they're being used.
customer = Customer.with.Order.with(:total => 22.21).thats.active.build
You can:
- specify defaults
- can be overridden
- reuse builders
- chain builders
- specialise builders
customer = Customer.with.Order.with(:total => 22.21).thats.active.build
class Customer end
class Order end
class CustomerBuilder end
class OrderBuilder end
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
- Association:
- single
- implement responds_to whereever method_missing implemented
- ponder adding default hash param to #with
- dynamically add the methods to builder, based on instance being built?
- many
- Build multiple: Customer.with.two.Orders
- linguistics gem for text to number conversion
- single
- Specialisation
- infer #make#{Something} method convention for specialisation methods on builder?
- #initialize and #build should be already available to builder
- #with and #thats can't be combined at present
- Reusing builders
- Replace String>>#to_class implementation from stack overflow article with a spec'd/tested version
- Alternative syntax:
- Order.thats.active.build => Build.order.thats.active
- Advantage is Class extension no longer needed
- How to know when to build the instance?