Class: BlueprintsBoy::Factories
- Inherits:
-
Object
- Object
- BlueprintsBoy::Factories
- Defined in:
- lib/blueprints_boy/factories.rb
Instance Method Summary collapse
- #[](factory_class, strategy) ⇒ Object
- #add(factory_class, strategy, &block) ⇒ Object
-
#initialize ⇒ Factories
constructor
A new instance of Factories.
Constructor Details
#initialize ⇒ Factories
Returns a new instance of Factories.
3 4 5 |
# File 'lib/blueprints_boy/factories.rb', line 3 def initialize @factories = Hash.new { |hash, key| hash[key] = {} } end |
Instance Method Details
#[](factory_class, strategy) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/blueprints_boy/factories.rb', line 11 def [](factory_class, strategy) factory_class.ancestors.each do |ancestor| return @factories[ancestor][strategy] if @factories.key?(ancestor) end raise FactoryNotFound, "Factory for #{factory_class} can't be located" end |
#add(factory_class, strategy, &block) ⇒ Object
7 8 9 |
# File 'lib/blueprints_boy/factories.rb', line 7 def add(factory_class, strategy, &block) @factories[factory_class][strategy] = block end |