Class: WrapperBased::Context
- Inherits:
-
Object
- Object
- WrapperBased::Context
show all
- Defined in:
- lib/wrapper_based/context.rb,
lib/wrapper_based/context/producer.rb
Defined Under Namespace
Modules: TypeCasting
Classes: Casting, CastingDirector, Producer
Constant Summary
collapse
- UnassignedRole =
Class.new(StandardError)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**where) ⇒ Context
Returns a new instance of Context.
3
4
5
6
|
# File 'lib/wrapper_based/context.rb', line 3
def initialize(**where)
@_casting_director_ = CastingDirector.new(self.class)
rebind where
end
|
Class Method Details
.call(**where) ⇒ Object
26
27
28
|
# File 'lib/wrapper_based/context.rb', line 26
def call(**where)
new(where).call
end
|
.cast_as(role, actor) ⇒ Object
30
31
32
|
# File 'lib/wrapper_based/context.rb', line 30
def cast_as(role, actor)
send(role).typecast(actor)
end
|
Instance Method Details
#[](*args, &block) ⇒ Object
17
18
19
|
# File 'lib/wrapper_based/context.rb', line 17
def [](*args, &block)
call(*args, &block)
end
|
#rebind(**where) ⇒ Object
8
9
10
11
|
# File 'lib/wrapper_based/context.rb', line 8
def rebind(**where)
where.each { |role, player| public_send :"#{role}=", player }
self
end
|
#to_proc ⇒ Object
13
14
15
|
# File 'lib/wrapper_based/context.rb', line 13
def to_proc
method(:call).to_proc
end
|