Class: KafoWizards::Factory
- Inherits:
-
Object
- Object
- KafoWizards::Factory
- Defined in:
- lib/kafo_wizards/factory.rb
Instance Method Summary collapse
-
#initialize(wizard = nil) ⇒ Factory
constructor
A new instance of Factory.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(wizard = nil) ⇒ Factory
Returns a new instance of Factory.
9 10 11 |
# File 'lib/kafo_wizards/factory.rb', line 9 def initialize(wizard=nil) @wizard = wizard end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kafo_wizards/factory.rb', line 13 def method_missing(meth, *args, &block) if @wizard args << {} unless args.last.class <= Hash args[-1][:parent] = @wizard unless args[-1].has_key?(:parent) end entry_cls = KafoWizards::Entries::AbstractEntry.descendants.find { |ec| ec.entry_type == meth } raise NameError.new "Unknown type of entry (#{meth.to_s})" unless entry_cls entry_cls.new(*args) end |