Module: Toritori::ClassMethods
- Defined in:
- lib/toritori.rb
Overview
Defines high level interface
Instance Method Summary collapse
- #create(name, *args, **kwargs, &block) ⇒ Object
- #factories ⇒ Object
- #factories=(other) ⇒ Object
- #factory(name, produces: Class.new, creation_method: :new, &block) ⇒ Object
- #inherited(subclass) ⇒ Object
Instance Method Details
#create(name, *args, **kwargs, &block) ⇒ Object
32 33 34 |
# File 'lib/toritori.rb', line 32 def create(name, *args, **kwargs, &block) factories[name].create(*args, **kwargs, &block) end |
#factories ⇒ Object
14 15 16 |
# File 'lib/toritori.rb', line 14 def factories @factories ||= {} end |
#factories=(other) ⇒ Object
18 19 20 |
# File 'lib/toritori.rb', line 18 def factories=(other) @factories = other end |
#factory(name, produces: Class.new, creation_method: :new, &block) ⇒ Object
22 23 24 25 |
# File 'lib/toritori.rb', line 22 def factory(name, produces: Class.new, creation_method: :new, &block) factories[name] = Toritori::Factory.new(name, base_class: produces, creation_method: creation_method, &block) define_singleton_method(:"#{name}_factory") { factories[name] } end |
#inherited(subclass) ⇒ Object
27 28 29 30 |
# File 'lib/toritori.rb', line 27 def inherited(subclass) super subclass.factories = factories.transform_values(&:copy) end |