Class: WrapperBased::Casting::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/wrapper_based/casting/pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(wrapper_for) ⇒ Pool

Returns a new instance of Pool.



3
4
5
6
7
# 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

Instance Method Details

#casting_for(*supporting_roles, **leading_roles) ⇒ Object



9
10
11
12
13
14
# 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) ⇒ Object



16
17
18
19
20
# 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