Class: WrapperBased::Context::Casting

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dci) ⇒ Casting

Returns a new instance of Casting.



7
8
9
10
11
# File 'lib/wrapper_based/context/casting.rb', line 7

def initialize(name, dci)
  @name = name.to_sym
  @casting = Set.new
  @dci = dci
end

Instance Attribute Details

#dciObject (readonly)

Returns the value of attribute dci.



5
6
7
# File 'lib/wrapper_based/context/casting.rb', line 5

def dci
  @dci
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/wrapper_based/context/casting.rb', line 5

def name
  @name
end

Instance Method Details

#as(extention) ⇒ Object



13
14
15
16
# File 'lib/wrapper_based/context/casting.rb', line 13

def as(extention)
  @casting << extention
  self
end

#cast_type(type) ⇒ Object



18
19
20
# File 'lib/wrapper_based/context/casting.rb', line 18

def cast_type(type)
  @dci.wrapper_for type, *@casting
end

#typecast(actor) ⇒ Object



22
23
24
25
# File 'lib/wrapper_based/context/casting.rb', line 22

def typecast(actor)
  return actor if @casting.empty?
  cast_type(actor.class).new actor
end