Class: WrapperBased::Casting::Director

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(talent_pool) ⇒ Director

Returns a new instance of Director.



5
# File 'lib/wrapper_based/casting/director.rb', line 5

def initialize(talent_pool) super(Casting.new, talent_pool) end

Instance Attribute Details

#castingObject

Returns the value of attribute casting

Returns:

  • (Object)

    the current value of casting



4
5
6
# File 'lib/wrapper_based/casting/director.rb', line 4

def casting
  @casting
end

#talent_poolObject

Returns the value of attribute talent_pool

Returns:

  • (Object)

    the current value of talent_pool



4
5
6
# File 'lib/wrapper_based/casting/director.rb', line 4

def talent_pool
  @talent_pool
end

Instance Method Details

#adds(role, talent = TALENTLESS) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/wrapper_based/casting/director.rb', line 7

def adds(role, talent = TALENTLESS)
  case talent
  when ::Proc, ::Method, ::Symbol
    casting.casts role, &talent
  when ::Class
    casting.casts role, &talent.method(:new)
  when ::Module
    casting.casts_as role, &type_for(role).has(talent).method(:typecast)
  else
    throw :wrong_talent_type, [role, talent, "expected Module, Class, Proc, Method or Symbol"]
  end
end

#to_procObject



20
21
22
# File 'lib/wrapper_based/casting/director.rb', line 20

def to_proc
  method(:adds).to_proc
end

#type_for(role) ⇒ Object



24
25
26
# File 'lib/wrapper_based/casting/director.rb', line 24

def type_for(role)
  Casting::Type.new(role, talent_pool)
end