Module: MiniTools::ItemFactory

Defined in:
lib/mini_tools/item_factory.rb

Overview

The ItemFactory is used for creating instances of classes based on a map of keys to classes. For example, assume we a list of commands to be run that looks something like this “‘ commands = [

[:notification_email, '[email protected]'],
[:update_account, ],

] “‘ Each of these commands has an associated Command object. Then we can create an ItemFactory to dynamically build the instances we need

“‘ class CommandFactory

include MiniTools::ItemFactory

map(
  notification_email: EmailNotifier,
  update_account: AccountUpdater
)

end

commands.each do |command, args|

CommandFactory.build(command).execute(args)

end “‘

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



31
32
33
# File 'lib/mini_tools/item_factory.rb', line 31

def self.included(base)
  base.extend(ClassMethods)
end