module MiniTools::ItemFactory

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, 'someone@somewhere.co.uk'],
[:update_account, account_instance],

] “` 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 “`

Public Class Methods

included(base) click to toggle source
# File lib/mini_tools/item_factory.rb, line 31
def self.included(base)
  base.extend(ClassMethods)
end