class WrapperBased::Casting::Pool

Public Class Methods

new(wrapper_for) click to toggle source
# File lib/wrapper_based/casting/pool.rb, line 3
def initialize(wrapper_for)
  @talent_pool = Hash.new do |cache, type_casting|
    cache[type_casting] = wrapper_for[*type_casting]
  end
end

Public Instance Methods

casting_for(*supporting_roles, **leading_roles) click to toggle source
# File lib/wrapper_based/casting/pool.rb, line 9
def casting_for(*supporting_roles, **leading_roles)
  WrapperBased::Casting::Director.new(@talent_pool).tap do |director|
    supporting_roles.each(&director)
    leading_roles.each { |role, talent| director.adds role, talent }
  end.casting
end
context_for(*roles, &script) click to toggle source
# File lib/wrapper_based/casting/pool.rb, line 16
def context_for(*roles, &script)
  klass = Class.new(Context).include casting_for(*roles)
  klass.class_exec(&script) if block_given?
  klass
end