Class: WrapperBased::DCI

Inherits:
Module
  • Object
show all
Defined in:
lib/wrapper_based/dci.rb

Instance Method Summary collapse

Constructor Details

#initialize(wrapper_for = FORWARDING) ⇒ DCI

Returns a new instance of DCI.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wrapper_based/dci.rb', line 3

def initialize(wrapper_for = FORWARDING)
  @@wrapper_for = Hash.new do |cache, type_casting|
    cache[type_casting] = wrapper_for[*type_casting]
  end unless defined? @@wrapper_for

  def wrapper_for(*type_casting)
    @@wrapper_for[type_casting]
  end unless defined? self.wrapper_for

  def Context(*roles, &block)
    dci = self
    Class.new(WrapperBased::Context) do
      roles.each { |role| add_role role, WrapperBased::Cast.new(role, dci) }
      class_eval(&block) unless block.nil?
    end
  end unless defined? self.Context
end

Instance Method Details

#Context(*roles, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/wrapper_based/dci.rb', line 12

def Context(*roles, &block)
  dci = self
  Class.new(WrapperBased::Context) do
    roles.each { |role| add_role role, WrapperBased::Cast.new(role, dci) }
    class_eval(&block) unless block.nil?
  end
end

#wrapper_for(*type_casting) ⇒ Object



8
9
10
# File 'lib/wrapper_based/dci.rb', line 8

def wrapper_for(*type_casting)
  @@wrapper_for[type_casting]
end